本文整理汇总了PHP中HTTP_Request::addRawPostData方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request::addRawPostData方法的具体用法?PHP HTTP_Request::addRawPostData怎么用?PHP HTTP_Request::addRawPostData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_Request
的用法示例。
在下文中一共展示了HTTP_Request::addRawPostData方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post
/**
* 投稿実行
*/
public function post()
{
$hr = new HTTP_Request($this->getPostUrl());
$hr->addHeader('X-WSSE', $this->wsse);
$hr->addHeader('Accept', 'application/x.atom+xml, application/xml, text/xml, */*');
$hr->addHeader('Authorization', 'WSSE profile="UsernameToken"');
$hr->addHeader('Content-Type', 'application/x.atom+xml');
$hr->addRawPostData($this->getRawdata());
$hr->setMethod(HTTP_REQUEST_METHOD_POST);
$hr->sendRequest();
$hr->clearPostData();
}
示例2: willRequest
function willRequest($request)
{
// お気に入り作成をフックする
if (preg_match("|^/favorites/create/(\\d+)|", $this->server->request['path'], $match)) {
$id = $match[1];
$url = $this->server->config['Twitter']['api'];
$url .= '/status/show/' . $id . '.json';
$req = new HTTP_Request($url);
if (isset($_SERVER["PHP_AUTH_USER"])) {
$req->setBasicAuth($_SERVER["PHP_AUTH_USER"], @$_SERVER["PHP_AUTH_PW"]);
}
$result = $req->sendRequest();
if (PEAR::isError($result)) {
return;
}
if ($req->getResponseCode() != 200) {
return;
}
$json = json_decode($req->getResponseBody());
$title = $json->text;
$href = 'http://twitter.com/' . $json->user->screen_name . '/status/' . $id;
$created = date('Y-m-d\\TH:i:s\\Z');
$nonce = pack('H*', sha1(md5(time())));
$pass_digest = base64_encode(pack('H*', sha1($nonce . $created . $this->server->config['Plugin']['HatenaBookmark']['password'])));
$wsse = 'UsernameToken Username="' . $this->server->config['Plugin']['HatenaBookmark']['id'] . '", ';
$wsse .= 'PasswordDigest="' . $pass_digest . '", ';
$wsse .= 'Nonce="' . base64_encode($nonce) . '",';
$wsse .= 'Created="' . $created . '"';
$req = new HTTP_Request('http://b.hatena.ne.jp/atom/post');
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addHeader('WWW-Authenticate', 'WSSE profile="UsernameToken"');
$req->addHeader('X-WSSE', $wsse);
$req->addHeader('Content-Type', 'application/x.atom+xml');
$xml = '<?xml version="1.0" encoding="utf-8"?>' . '<entry xmlns="http://purl.org/atom/ns#">' . '<title>' . $title . '</title>' . '<link rel="related" type="text/html" href="' . $href . '" />' . '<summary type="text/plain"></summary>' . '</entry>';
$req->addRawPostData($xml);
$req->sendRequest();
}
return $request;
}
示例3: switch
/**
* Stream handler interface lock() method (experimental ...)
*
* @access private
* @return bool true on success else false
*/
function stream_lock($mode)
{
/* TODO:
- think over how to refresh locks
*/
$ret = false;
// LOCK is only supported by DAV Level 2
if (!isset($this->dav_level["2"])) {
return false;
}
switch ($mode & ~LOCK_NB) {
case LOCK_UN:
if ($this->locktoken) {
$req = new HTTP_Request($this->url);
$req->setMethod(HTTP_REQUEST_METHOD_UNLOCK);
if (is_string($this->user)) {
$req->setBasicAuth($this->user, @$this->pass);
}
$req->addHeader("Lock-Token", "<{$this->locktoken}>");
$req->sendRequest();
$ret = $req->getResponseCode() == 204;
}
break;
case LOCK_SH:
case LOCK_EX:
$body = sprintf('<?xml version="1.0" encoding="utf-8" ?>
<D:lockinfo xmlns:D="DAV:">
<D:lockscope><D:%s/></D:lockscope>
<D:locktype><D:write/></D:locktype>
<D:owner>%s</D:owner>
</D:lockinfo>', $mode & LOCK_SH ? "shared" : "exclusive", get_class($this));
// TODO better owner string
$req = new HTTP_Request($this->url);
$req->setMethod(HTTP_REQUEST_METHOD_LOCK);
if (is_string($this->user)) {
$req->setBasicAuth($this->user, @$this->pass);
}
if ($this->locktoken) {
// needed for refreshing a lock
$req->addHeader("Lock-Token", "<{$this->locktoken}>");
}
$req->addHeader("Timeout", "Infinite, Second-4100000000");
$req->addHeader("Content-Type", 'text/xml; charset="utf-8"');
$req->addRawPostData($body);
$req->sendRequest();
$ret = $req->getResponseCode() == 200;
if ($ret) {
$propinfo = new HTTP_WebDAV_Client_parse_lock_response($req->getResponseBody());
$this->locktoken = $propinfo->locktoken;
// TODO deal with timeout
}
break;
default:
break;
}
return $ret;
}
示例4: switch
//.........这里部分代码省略.........
</label><br />
<?php
}
?>
<input onclick="<?php
echo $noneclick;
?>
" class="input_checkbox" style="margin: 0px; padding: 0px; vertical-align: bottom;" type="checkbox" value="none" id="serendipity[announce_entries_none]" />
<label title="<?php
echo NONE;
?>
" style="vertical-align: bottom; margin: 0px; padding: 0px;" for="serendipity[announce_entries_none]"> <?php
echo NONE;
?>
</label><br />
</fieldset>
<?php
return true;
break;
case 'backend_publish':
if (!class_exists('XML_RPC_Base')) {
include_once S9Y_PEAR_PATH . "XML/RPC.php";
}
// First cycle through list of services to remove superseding services which may have been checked
foreach ($this->services as $index => $service) {
if (!empty($service['supersedes']) && isset($serendipity['POST']['announce_entries_' . $service['name']])) {
$supersedes = explode(', ', $service['supersedes']);
foreach ($supersedes as $sid => $servicename) {
// A service has been checked that is superseded by another checked meta-service. Remove that service from the list of services to be ping'd
unset($serendipity['POST']['announce_entries_' . $servicename]);
}
}
}
foreach ($this->services as $index => $service) {
if (isset($serendipity['POST']['announce_entries_' . $service['name']]) || defined('SERENDIPITY_IS_XMLRPC') && serendipity_db_bool($this->get_config($service['name']))) {
if (!defined('SERENDIPITY_IS_XMLRPC') || defined('SERENDIPITY_XMLRPC_VERBOSE')) {
printf(PLUGIN_EVENT_WEBLOGPING_SENDINGPING . '...', $service['host']);
}
flush();
# XXX append $serendipity['indexFile'] to baseURL?
$args = array(new XML_RPC_Value($serendipity['blogTitle'], 'string'), new XML_RPC_Value($serendipity['baseURL'], 'string'));
if ($service['extended']) {
# the checkUrl: for when the main page is not really the main page
$args[] = new XML_RPC_Value('', 'string');
# the rssUrl
$args[] = new XML_RPC_Value($serendipity['baseURL'] . 'rss.php?version=2.0', 'string');
}
$message = new XML_RPC_Message($service['extended'] ? 'weblogUpdates.extendedPing' : 'weblogUpdates.ping', $args);
$client = new XML_RPC_Client(trim($service['path']), trim($service['host']));
# 15 second timeout may not be long enough for weblogs.com
$message->createPayload();
$options = array();
serendipity_plugin_api::hook_event('backend_http_request', $options, 'weblogping');
serendipity_request_start();
$req = new HTTP_Request("http://" . $service['host'] . $service['path'], $options);
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addHeader("Content-Type", "text/xml");
if (strtoupper(LANG_CHARSET) != 'UTF-8') {
$payload = utf8_encode($message->payload);
} else {
$payload = $message->payload;
}
$req->addRawPostData($payload);
$http_result = $req->sendRequest();
$http_response = $req->getResponseBody();
$xmlrpc_result = $message->parseResponse($http_response);
if ($xmlrpc_result->faultCode()) {
$out = sprintf(PLUGIN_EVENT_WEBLOGPING_SEND_FAILURE . "<br />", htmlspecialchars($xmlrpc_result->faultString()));
} else {
$out = PLUGIN_EVENT_WEBLOGPING_SEND_SUCCESS . "<br />";
}
serendipity_request_end();
if (!defined('SERENDIPITY_IS_XMLRPC') || defined('SERENDIPITY_XMLRPC_VERBOSE')) {
echo $out;
}
}
}
return true;
break;
case 'external_plugin':
if ($eventData == 'xmlrpc_ping') {
echo "XMLRPC START\n";
@define('SERENDIPITY_IS_XMLRPC', true);
@define('SERENDIPITY_XMLRPC_VERBOSE', true);
$this->event_hook('backend_publish', $bag, $eventData);
echo "XMLRPC DONE\n";
}
return true;
case 'frontend_display':
case 'backend_insert':
case 'backend_update':
case 'backend_draft':
default:
return false;
break;
}
} else {
return false;
}
}
示例5: _serendipity_send
/**
* Send a track/pingback ping
*
* @access public
* @param string The URL to send a trackback to
* @param string The XML data with the trackback contents
* @return string Reponse
*/
function _serendipity_send($loc, $data, $contenttype = null)
{
global $serendipity;
$target = parse_url($loc);
if ($target['query'] != '') {
$target['query'] = '?' . str_replace('&', '&', $target['query']);
}
if ($target['scheme'] == 'https' && empty($target['port'])) {
$uri = $target['scheme'] . '://' . $target['host'] . $target['path'] . $target['query'];
} elseif (!is_numeric($target['port'])) {
$target['port'] = 80;
$uri = $target['scheme'] . '://' . $target['host'] . ':' . $target['port'] . $target['path'] . $target['query'];
}
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
$options = array('allowRedirects' => true, 'maxRedirects' => 5, 'method' => 'POST');
serendipity_plugin_api::hook_event('backend_http_request', $options, 'trackback_send');
serendipity_request_start();
$req = new HTTP_Request($uri, $options);
if (isset($contenttype)) {
$req->addHeader('Content-Type', $contenttype);
}
$req->addRawPostData($data, true);
$res = $req->sendRequest();
if (PEAR::isError($res)) {
serendipity_request_end();
return false;
}
$fContent = $req->getResponseBody();
serendipity_request_end();
return $fContent;
}
示例6: renewItems
/**
* Try to renew a list of item barcodes
* - Return the new list of items on loan, with some errors
* built in to the data structure.
*
* @param array $patron The patron array from patronLogin
* @param array $item_list Array of barcodes to renew
*
* @return array Renewal status information
* @access public
*/
public function renewItems($patron, $item_list)
{
// Get items out on loan at the moment
$result = $this->getMyTransactions($patron);
// Make it more accessible - by barcode
$initial = array();
foreach ($result as $row) {
$initial[$row['barcode']] = $row;
}
// Get the iPortal server
$web_server = $this->_config['Catalog']['webhost'];
// Fake a login to get an authenticated session
$session_id = $this->_fakeLogin($patron);
$virtua_url = "http://{$web_server}/cgi-bin/chameleon";
$client = new HTTP_Request();
$client->setMethod(HTTP_REQUEST_METHOD_POST);
$client->setURL($virtua_url);
// Have to use addRawPostData() because of the way
// virtua expects the barcodes to come across.
// You can't mix addPostData() and addRawPostData()
// so they are all raw.
$post_data = "function=" . "RENEWAL";
$post_data .= "&search=" . "PATRON";
$post_data .= "&sessionid=" . "{$session_id}";
$post_data .= "&skin=" . "homepage";
$post_data .= "&lng=" . "en";
$post_data .= "&inst=" . "consortium";
$post_data .= "&conf=" . urlencode("./chameleon.conf");
$post_data .= "&u1=" . "12";
$post_data .= "&SourceScreen=" . "PATRONACTIVITY";
$post_data .= "&pos=" . "1";
$post_data .= "&patronid=" . $patron['cat_username'];
$post_data .= "&patronhost=" . urlencode($this->_config['Catalog']['patron_host']);
$post_data .= "&host=" . urlencode($this->_config['Catalog']['host_string']);
$post_data .= "&itembarcode=" . implode("&itembarcode=", $item_list);
$post_data .= "&submit=" . "Renew";
$post_data .= "&reset=" . "Clear";
$client->addRawPostData($post_data);
$result = $client->sendRequest();
// We don't care about errors, because we'll
// simply test for a change in the data.
// Get items out on loan with renewed info
$result = $this->getMyTransactions($patron);
// Foreach item currently on loan
$return = array();
foreach ($result as $row) {
// Did we even attempt to renew?
if (in_array($row['barcode'], $item_list)) {
// Yes, so check if the due date changed
if ($row['duedate'] != $initial[$row['barcode']]['duedate']) {
$row['error'] = false;
$row['renew_text'] = "Item successfully renewed.";
} else {
$row['error'] = true;
$row['renew_text'] = "Item renewal failed.";
}
$return[] = $row;
} else {
// No attempt to renew this item
$return[] = $row;
}
}
return $return;
}
示例7: class
/**
* sends a request to FedEx using pear HTTP_Request
*
* @return string
* @access private
*/
function _sendHTTP()
{
require_once "HTTP/Request.php";
$params = array_merge(array('timeout' => REQUEST_TIMEOUT), $this->request_params);
$req = new HTTP_Request($this->fedex_uri, $params);
$req->addHeader('User-Agent', $this->NAME . '-' . $this->VERSION . ' class ( http://www.vermonster.com )');
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addRawPostData($this->sBuf);
$response = $req->sendRequest();
if (PEAR::isError($response)) {
$this->setError("HTTP_Request Error: " . $response->getMessage());
return;
} else {
$this->httpBody = $req->getResponseBody();
}
return $this->httpBody;
}
示例8: request
/**
* Generates an API request
*
* @param $path string The path, eg "slices"
* @param $id string The id of the object, optional and really only used for slices and zones
* @param $action string Any action to take on the object, for instance "reboot"
* @param $method string The HTTP method for the request
* @param $parameters array Any post/query string parameters
* @param $postbody string The raw postbody, used in lieu of $parameters
* @return string The response body
*/
public function request($path,$id=null,$action=null,$method='GET',$parameters=null,$postbody=null,$cached=false)
{
// append slashes where needed
if ($id!='')
$path.='/';
if (($action!=null) && ($id!=null))
$id.='/';
// build the url
$url="https://api.slicehost.com/{$path}{$id}{$action}.xml";
if ($cached)
{
if (isset(self::$_cache[$url]))
{
return self::$_cache[$url];
}
}
// create a request
$request=new HTTP_Request($url);
// set the auth
$request->setBasicAuth($this->key,'');
// set the method
$method=strtoupper($method);
$request->setMethod($method);
// $postbody was specified, so this is an xml request
if ($postbody)
{
$request->addHeader('Content-Type','text/xml');
$request->addRawPostData($postbody);
}
// since we are posting well formed xml documents instead of
// post data, all the parameters will be appended as query strings
// since they are only used in the api in weird places.
if ($parameters)
foreach($parameters as $key=>$value)
$request->addQueryString($key,$value);
// send it off
$request->sendRequest(true);
// if success, build the response objects, otherwise throw an exception.
$repcode=$request->getResponseCode();
switch($repcode)
{
case 200:
case 201:
case 204:
$result=$this->build_response($request->getResponseBody());
self::$_cache[$url]=$result;
return $result;
default:
throw new SlicehostException("$url.\nResponse Code $repcode.\n\n{$request->getResponseBody()}\n\n");
}
}
示例9: getRecordById
/**
* retrieve a specific metadata with UUID in GeoNetwork / Geosource
* @param String $id of the metadata
* @return XML content (could be an empty response)
*/
public function getRecordById($id)
{
$getRecodByIDRequest = new HTTP_Request($this->_cswAddress);
$getRecodByIDRequest->addHeader("Content-Type", "text/xml");
$getRecodByIDRequest->setMethod(HTTP_REQUEST_METHOD_POST);
$request = $this->buildGetRecordById($id);
$getRecodByIDRequest->addRawPostData($request, true);
//authentication if needed
if (!$this->_authentication($getRecodByIDRequest)) {
throw new Exception($this->_response, "001");
}
if ($this->_callHTTPCSW($getRecodByIDRequest)) {
$getRecodByIDRequest = null;
return $this->_response;
} else {
$getRecodByIDRequest = null;
throw new Exception($this->_response, "002");
}
}
示例10: callMethod
function callMethod($method, $params = array())
{
$this->_err_code = 0;
$this->_err_msg = '';
#
# create the POST body
#
$p = $params;
$p['method'] = $method;
$p['api_key'] = $this->_cfg['api_key'];
if ($this->_cfg['api_secret']) {
$p['api_sig'] = $this->signArgs($p);
}
$p2 = array();
foreach ($p as $k => $v) {
$p2[] = urlencode($k) . '=' . urlencode($v);
}
$body = implode('&', $p2);
#
# create the http request
#
$req = new HTTP_Request($this->_cfg['endpoint'], array('timeout' => $this->_cfg['conn_timeout']));
$req->_readTimeout = array($this->_cfg['io_timeout'], 0);
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addRawPostData($body);
$req->sendRequest();
$this->_http_code = $req->getResponseCode();
$this->_http_head = $req->getResponseHeader();
$this->_http_body = $req->getResponseBody();
if ($this->_http_code != 200) {
$this->_err_code = 0;
if ($this->_http_code) {
$this->_err_msg = "Bad response from remote server: HTTP status code {$this->_http_code}";
} else {
$this->_err_msg = "Couldn't connect to remote server";
}
return 0;
}
#
# create xml tree
#
$dom = new DOMDocument();
$dom->loadXML($this->_http_body);
$xp = new DOMXPath($dom);
#
# check we got an <rsp> element at the root
#
if (!$xp->query("/rsp")->length) {
$this->_err_code = 0;
$this->_err_msg = "Bad XML response";
return 0;
}
#
# stat="fail" ?
#
$stat = $xp->query("/rsp/@stat")->item(0)->value;
if ($stat == 'fail') {
$n = null;
foreach ($xp->query("/rsp/err") as $err) {
$this->_err_code = $xp->query("@code", $err)->item(0)->value;
$this->_err_msg = $xp->query("@msg", $err)->item(0)->value;
}
return 0;
}
#
# weird status
#
if ($stat != 'ok') {
$this->_err_code = 0;
$this->_err_msg = "Unrecognised REST response status";
return 0;
}
#
# return the tree
#
return array($dom, $xp, $this->_http_body);
}
示例11: requestSend
function requestSend($url, $method, $headers, $rawdata = null)
{
// PEARのエラーを一時的に無効化
$E = error_reporting();
if (($E & E_STRICT) == E_STRICT) {
error_reporting($E ^ E_STRICT);
}
$result = null;
$request = new HTTP_Request($url);
if (strtoupper($method) == "POST") {
$request->setMethod(HTTP_REQUEST_METHOD_POST);
} else {
$request->setMethod(HTTP_REQUEST_METHOD_GET);
}
foreach ($headers as $key => $val) {
$request->addHeader($key, $val);
}
if ($rawdata) {
$request->addRawPostData($rawdata);
}
$request->sendRequest();
if (floor($request->getResponseCode() / 100) == 2) {
$result = $request->getResponseBody();
}
// error_reportingを元に戻す
error_reporting($E);
return $result;
}