本文整理汇总了PHP中HTTP_Request::setBody方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request::setBody方法的具体用法?PHP HTTP_Request::setBody怎么用?PHP HTTP_Request::setBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_Request
的用法示例。
在下文中一共展示了HTTP_Request::setBody方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exportarDados
/**
* Método que encapsula a chamada do WEB SERVICE que traduz um arquivo .HTML em outras extensões.
* Utilizado para exportar dados para arquivos a desejo do usuário.
*
* @param texto $arquivoFetch nome do arquivo a ser utilizado para exportação, desde a pasta 'html'.
* @param texto $extensaoDestino mine type para arquivo exportado.
* @param texto $nomeArquivo nome a ser exibido no download do arquivo.
*/
function exportarDados($arquivoFetch, $nomeArquivo = "Relatório.pdf", $extensaoDestino = "application/pdf", $fazerDownload = true)
{
$codigoHtml = $this->smarty->fetch($arquivoFetch);
$codigoHtml = str_replace("html/css/", URL_COMPLETA . "html/css/", $codigoHtml);
$codigoHtml = str_replace("html/img/", URL_COMPLETA . "html/img/", $codigoHtml);
$request = new HTTP_Request(WEBSERVICE_BROFFICE_URL);
$request->setMethod("POST");
$request->addHeader("Content-Type", "text/html");
$request->addHeader("Accept", $extensaoDestino);
$request->setBody($codigoHtml);
$request->sendRequest();
$status = $request->getResponseCode();
//echo $request->getResponseBody(); die;
if ($status != 200) {
echo "Ocorreu um erro na conversão. Favor entrar em contato com o administrador.";
die;
}
if ($fazerDownload) {
header("Content-Type: " . $extensaoDestino . "\n");
header("Content-Disposition: attachment; filename=" . $nomeArquivo);
echo $request->getResponseBody();
die;
}
return $request->getResponseBody();
}
示例2: addEvent
/**
* Add Google Calendar Event.
*
*
* @param String $cal_url
* @param String $eTitle
* @param String $eDesc
* @param String $eAuthorName
* @param String $eAuthorEmail
* @param String $eLocation
* @param String $eStartTime ISO Formatted Date (see: date('c'))
* @param String $eEndTime ISO Formatted Date
* @return boolean False on Failure.
*/
public function addEvent($cal_url, $eTitle, $eDesc, $eAuthorName, $eAuthorEmail, $eLocation, $eStartTime, $eEndTime)
{
/* Make sure we send ONLY valid XML. */
$eTitle = htmlentities($eTitle);
$eDesc = htmlentities($eDesc);
$eAuthorName = htmlentities($eAuthorName);
$eAuthorEmail = htmlentities($eAuthorEmail);
$eLocation = htmlentities($eLocation);
$eStartTime = htmlentities($eStartTime);
$eEndTime = htmlentities($eEndTime);
$xml = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>\n \t\t\t\t<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'></category>\n \t\t\t\t<title type='text'>{$eTitle}</title>\n \t\t\t\t<content type='text'>{$eDesc}</content>\n \t\t\t\t<author>\n \t\t\t\t<name>{$eAuthorName}</name>\n \t\t\t\t<email>{$eAuthorEmail}</email>\n \t\t\t\t</author>\n \t\t\t\t<gd:transparency value='http://schemas.google.com/g/2005#event.opaque'></gd:transparency>\n \t\t\t\t<gd:eventStatus\n \t\t\t\tvalue='http://schemas.google.com/g/2005#event.confirmed'>\n \t\t\t\t</gd:eventStatus>\n \t\t\t\t<gd:where valueString='{$eLocation}'></gd:where>\n \t\t\t\t<gd:when startTime='{$eStartTime}'\n \t\t\t\tendTime='{$eEndTime}'></gd:when>\n\t\t\t</entry>";
$http = new HTTP_Request($cal_url, array('allowRedirects' => true));
$http->setMethod('POST');
$http->addHeader('Host', 'www.google.com');
$http->addHeader('MIME-Version', '1.0');
$http->addHeader('Accept', 'text/xml');
$http->addHeader('Content-type', 'application/atom+xml');
$http->addHeader('Authorization', 'GoogleLogin auth=' . $this->token);
$http->addHeader('Content-length', strlen($xml));
$http->addHeader('Cache-Control', 'no-cache');
$http->addHeader('Connection', 'close');
$http->setBody($xml);
$http->sendRequest();
switch ($http->getResponseCode()) {
case 201:
case 200:
return true;
break;
default:
throw new Exception('Error Adding Google Cal Event. Response From Google:' . $http->getResponseBody(), $http->getResponseCode());
return false;
break;
}
}
示例3: _update
/**
* Submit REST Request to write data
*
* @param string $xml The command to execute
* @return mixed Boolean true on success or PEAR_Error
* @access private
*/
private function _update($xml)
{
global $configArray;
global $timer;
$this->client->setMethod('POST');
$this->client->setURL($this->host . "/update/");
if ($this->debug) {
echo "<pre>POST: ";
print_r($this->host . "/update/");
echo "XML:\n";
print_r($xml);
echo "</pre>\n";
}
// Set up XML
$this->client->addHeader('Content-Type', 'text/xml; charset=utf-8');
$this->client->addHeader('Content-Length', strlen($xml));
$this->client->setBody($xml);
// Send Request
$result = $this->client->sendRequest();
$responseCode = $this->client->getResponseCode();
//$this->client->clearPostData();
if ($responseCode == 500 || $responseCode == 400) {
$detail = $this->client->getResponseBody();
$timer->logTime("Send the update request");
// Attempt to extract the most useful error message from the response:
if (preg_match("/<title>(.*)<\\/title>/msi", $detail, $matches)) {
$errorMsg = $matches[1];
} else {
$errorMsg = $detail;
}
global $logger;
$logger->log("Error updating document\r\n{$xml}", PEAR_LOG_DEBUG);
return new PEAR_Error("Unexpected response -- " . $errorMsg);
} elseif ($configArray['System']['debugSolr'] == true) {
$this->client->getResponseBody();
$timer->logTime("Get response body");
// Attempt to extract the most useful error message from the response:
//print_r("Update Response:");
//print_r($detail);
}
if (!PEAR_Singleton::isError($result)) {
return true;
} else {
return $result;
}
}
示例4: SendRequest
public function SendRequest($data)
{
if (defined('OX_DEBUG') && OX_DEBUG == 1) {
ob_start();
var_dump($data);
$rdata = ob_get_contents();
ob_end_clean();
debugLog("request: {$rdata}");
}
$request = new HTTP_Request(OX_URL . "/multiple", array("method" => "PUT"));
foreach ($this->cookies as $cookie) {
$request->addCookie($cookie["name"], $cookie["value"]);
}
$request->addQueryString("session", $this->session);
//$request->addHeader("Content-Type", "text/javascript");
$request->setBody("[" . $this->json->encodeUnsafe($data) . "]");
try {
$request->sendRequest();
if ($request->getResponseCode() == 200) {
$reply = $this->json->decode($request->getResponseBody());
if (defined('OX_DEBUG') && OX_DEBUG == 1) {
ob_start();
var_dump($reply);
$rdata = ob_get_contents();
ob_end_clean();
debugLog("reply: {$rdata}");
}
return $reply[0];
} else {
return false;
}
} catch (HTTP_Exception $e) {
echo $e->getMessage();
return false;
}
}
示例5: array
function _request($url, $body = null, $content_type = 'text/html', $method = 'GET', $headers = array(), $cookies = array())
{
set_include_path(_XE_PATH_ . "libs/PEAR");
require_once 'PEAR.php';
require_once 'HTTP/Request.php';
$url_info = parse_url($url);
$host = $url_info['host'];
if (__PROXY_SERVER__ !== null) {
$oRequest = new HTTP_Request(__PROXY_SERVER__);
$oRequest->setMethod('POST');
$oRequest->addPostData('arg', serialize(array('Destination' => $url, 'method' => $method, 'body' => $body, 'content_type' => $content_type, "headers" => $headers)));
} else {
$oRequest = new HTTP_Request($url);
if (count($headers)) {
foreach ($headers as $key => $val) {
$oRequest->addHeader($key, $val);
}
}
if ($cookies[$host]) {
foreach ($cookies[$host] as $key => $val) {
$oRequest->addCookie($key, $val);
}
}
if (!$content_type) {
$oRequest->addHeader('Content-Type', 'text/html');
} else {
$oRequest->addHeader('Content-Type', $content_type);
}
$oRequest->setMethod($method);
if ($body) {
$oRequest->setBody($body);
}
}
$oResponse = $oRequest->sendRequest();
$code = $oRequest->getResponseCode();
$header = $oRequest->getResponseHeader();
$response = $oRequest->getResponseBody();
if ($c = $oRequest->getResponseCookies()) {
foreach ($c as $k => $v) {
$cookies[$host][$v['name']] = $v['value'];
}
}
if ($code > 300 && $code < 399 && $header['location']) {
return $this->_request($header['location'], $body, $content_type, $method, $headers, $cookies);
}
if ($code != 200) {
return;
}
return $response;
}
示例6: getRemoteResource
function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array())
{
requirePear();
require_once 'HTTP/Request.php';
$parsed_url = parse_url(__PROXY_SERVER__);
if ($parsed_url["host"]) {
$oRequest = new HTTP_Request(__PROXY_SERVER__);
$oRequest->setMethod('POST');
$oRequest->_timeout = $timeout;
$oRequest->addPostData('arg', serialize(array('Destination' => $url, 'method' => $method, 'body' => $body, 'content_type' => $content_type, "headers" => $headers, "post_data" => $post_data)));
} else {
$oRequest = new HTTP_Request($url);
if (count($headers)) {
foreach ($headers as $key => $val) {
$oRequest->addHeader($key, $val);
}
}
if ($cookies[$host]) {
foreach ($cookies[$host] as $key => $val) {
$oRequest->addCookie($key, $val);
}
}
if (count($post_data)) {
foreach ($post_data as $key => $val) {
$oRequest->addPostData($key, $val);
}
}
if (!$content_type) {
$oRequest->addHeader('Content-Type', 'text/html');
} else {
$oRequest->addHeader('Content-Type', $content_type);
}
$oRequest->setMethod($method);
if ($body) {
$oRequest->setBody($body);
}
$oRequest->_timeout = $timeout;
}
$oResponse = $oRequest->sendRequest();
$code = $oRequest->getResponseCode();
$header = $oRequest->getResponseHeader();
$response = $oRequest->getResponseBody();
if ($c = $oRequest->getResponseCookies()) {
foreach ($c as $k => $v) {
$cookies[$host][$v['name']] = $v['value'];
}
}
if ($code > 300 && $code < 399 && $header['location']) {
return FileHandler::getRemoteResource($header['location'], $body, $timeout, $method, $content_type, $headers, $cookies, $post_data);
}
return $response;
}
示例7: post_file_s3
/**
* @param $object_id Name to assign
* @param $content_bytes Content of file
* @param $mime_type MIME/Type to assign
* @return mixed URL of uploaded file on success, false or PEAR_Error on failure.
*/
function post_file_s3($object_id, $content_bytes, $mime_type)
{
$bucket_id = S3_BUCKET_ID;
$content_md5_hex = md5($content_bytes);
$date = date('D, d M Y H:i:s T');
$content_md5 = '';
for ($i = 0; $i < strlen($content_md5_hex); $i += 2) {
$content_md5 .= chr(hexdec(substr($content_md5_hex, $i, 2)));
}
$content_md5 = base64_encode($content_md5);
$sign_string = "PUT\n{$content_md5}\n{$mime_type}\n{$date}\nx-amz-acl:public-read\n/{$bucket_id}/{$object_id}";
//error_log("String to sign: {$sign_string}");
$crypt_hmac = new Crypt_HMAC(AWS_SECRET_KEY, 'sha1');
$hashed = $crypt_hmac->hash($sign_string);
$signature = '';
for ($i = 0; $i < strlen($hashed); $i += 2) {
$signature .= chr(hexdec(substr($hashed, $i, 2)));
}
$authorization = sprintf('AWS %s:%s', AWS_ACCESS_KEY, base64_encode($signature));
//error_log("Authorization header: {$authorization}");
$url = "http://{$bucket_id}.s3.amazonaws.com/{$object_id}";
$req = new HTTP_Request($url);
$req->setMethod('PUT');
$req->addHeader('Date', $date);
$req->addHeader('X-Amz-Acl', 'public-read');
$req->addHeader('Content-Type', $mime_type);
$req->addHeader('Content-MD5', $content_md5);
$req->addHeader('Content-Length', strlen($content_bytes));
$req->addHeader('Authorization', $authorization);
$req->setBody($content_bytes);
$res = $req->sendRequest();
if (PEAR::isError($res)) {
return $res;
}
if ($req->getResponseCode() == 200) {
return $url;
}
return false;
}
示例8: sendRequest
function sendRequest($resource, $verb = NULL, $objectdata = NULL, $acl = NULL, $contentType = NULL, $metadata = NULL)
{
if ($verb == NULL) {
$verb = $this->verb;
}
if ($acl == NULL) {
$aclstring = "";
} else {
$aclstring = "x-amz-acl:{$acl}\n";
}
$contenttypestring = "";
if ($contentType != NULL && $verb == "PUT" && $objectdata != NULL && $objectdata != "") {
$contenttypestring = "{$contentType}";
}
// update date / time on each request
$this->httpDate = gmdate($this->date_format);
$httpDate = $this->httpDate;
$paramstring = "";
$delim = "?";
if (strlen($this->prefix)) {
$paramstring .= $delim . "prefix=" . urlencode($this->prefix);
$delim = "&";
}
if (strlen($this->marker)) {
$paramstring .= $delim . "marker=" . urlencode($this->marker);
$delim = "&";
}
if (strlen($this->max_keys)) {
$paramstring .= $delim . "max-keys=" . $this->max_keys;
$delim = "&";
}
if (strlen($this->delimiter)) {
$paramstring .= $delim . "delimiter=" . urlencode($this->delimiter);
$delim = "&";
}
$this->debug_text("HTTP Request sent to: " . $this->S3_URL . $resource . $paramstring);
$req = new HTTP_Request($this->S3_URL . $resource . $paramstring);
$req->setMethod($verb);
if ($objectdata != NULL && $objectdata != "") {
$contentMd5 = $this->hex2b64(md5($objectdata));
$req->addHeader("CONTENT-MD5", $contentMd5);
$this->debug_text("MD5 HASH OF DATA: " . $contentMd5);
$contentmd5string = $contentMd5;
} else {
$contentmd5string = "";
}
if (strlen($contenttypestring)) {
$this->debug_text("Setting content type to {$contentType}");
$req->addHeader("CONTENT-TYPE", $contentType);
}
$req->addHeader("DATE", $httpDate);
if (strlen($aclstring)) {
$this->debug_text("Setting acl string to {$acl}");
$req->addHeader("x-amz-acl", $acl);
}
$metadatastring = "";
if (is_array($metadata)) {
ksort($metadata);
$this->debug_text("Metadata found.");
foreach ($metadata as $key => $value) {
$metadatastring .= "x-amz-meta-" . $key . ":" . trim($value) . "\n";
$req->addHeader("x-amz-meta-" . $key, trim($value));
$this->debug_text("Setting x-amz-meta-{$key} to '{$value}'");
}
}
if ($objectdata != NULL && $objectdata != "") {
$req->setBody($objectdata);
}
$stringToSign = "{$verb}\n{$contentmd5string}\n{$contenttypestring}\n{$httpDate}\n{$aclstring}{$metadatastring}/{$resource}";
$this->debug_text("Signing String: {$stringToSign}");
$signature = $this->hex2b64($this->hasher->hash($stringToSign));
$req->addHeader("Authorization", "AWS " . $this->keyId . ":" . $signature);
$req->sendRequest();
$this->_responseContentType = $req->getResponseHeader("content-type");
if (strlen($req->getResponseBody())) {
$this->debug_text($req->getResponseBody());
return $req->getResponseBody();
} else {
$this->debug_text($req->getResponseHeader());
return $req->getResponseHeader();
}
}
示例9: httpMe
private function httpMe($http_cmd, $cloudcache_cmd, $path, $data = '', array $aditional_headers = array())
{
$ts = gmdate('Y-m-d\\TH:G:s\\Z');
$userAgent = 'CloudCache PHP Client';
$sig = base64_encode(hash_hmac('sha1', 'CloudCache' . $cloudcache_cmd . $ts, $this->_skey, true));
$req = new HTTP_Request('http://' . $this->_host . '/' . $path);
$req->setMethod($http_cmd);
$req->addHeader("User-Agent", $userAgent);
$req->addHeader("timestamp", $ts);
$req->addHeader("signature", $sig);
$req->addHeader("akey", $this->_akey);
$req->setBody($data);
$req->sendRequest();
$ct = $req->getResponseHeader("content-type");
$rspCode = $req->getResponseCode();
return $req->getResponseBody();
}
示例10: shuttle_url
//.........这里部分代码省略.........
// open a stream and send the request
$fp = fopen($url, 'r', false, $context);
if (!$fp) {
$err = PEAR::raiseError(sprintf('Cannot connect to %s.', $url));
self::push_error($err);
return $err;
}
if ($outsec >= 0) {
stream_set_timeout($fp, $outsec);
}
// process the response
$meta_data = stream_get_meta_data($fp);
if (strcasecmp($meta_data['wrapper_type'], 'cURL') == 0) {
$errmsg = 'EstraierPure does not work with the cURL'
. ' HTTP stream wrappers, please use PEAR::HTTP_Request.';
$err = PEAR::raiseError($errmsg);
self::push_error($err);
return $err;
}
if (!empty($meta_data['timed_out'])) {
$err = PEAR::raiseError('Connection timed out.');
self::push_error($err);
return $err;
}
$first_header = array_shift($meta_data['wrapper_data']);
if (!preg_match('!^HTTP/(.+?) (\\d+) ?(.*)!', $first_header, $matches)) {
$err = PEAR::raiseError('Malformed response.');
self::push_error($err);
return $err;
}
$code = intval($matches[2]);
if ($res instanceof EstraierPure_Response) {
if ($res->save_heads) {
foreach ($meta_data['wrapper_data'] as $header) {
list($name, $value) = explode(':', $header, 2);
$res->add_head(strtolower($name), ltrim($value));
}
}
if ($res->save_body) {
$res->set_body(stream_get_contents($fp));
}
}
// close the stream
fclose($fp);
// }}}
} else {
// {{{{ using PEAR::HTTP_Request
// set request parameters
$params = array();
$params['requestHeaders'] = $reqheads;
if (isset($params['requestHeaders']['Content-Type'])) {
unset($params['requestHeaders']['Content-Type']);
$params['requestHeaders']['content-type'] = $reqheads['Content-Type'];
}
if (!is_null($pxhost)) {
$params['proxy_host'] = $pxhost;
$params['proxy_port'] = $pxport;
}
if ($outsec >= 0) {
$params['timeout'] = floatval($outsec);
$params['readTimeout'] = array($outsec, 0);
}
// create an instance of HTTP_Request
$req = new HTTP_Request($url, $params);
if (is_null($reqbody)) {
$req->setMethod('GET');
} else {
$req->setMethod('POST');
$req->setBody($reqbody);
}
// send the request
$err = $req->sendRequest(is_object($res) && !empty($res->save_body));
if (PEAR::isError($err)) {
self::push_error($err);
return $err;
}
$code = $req->getResponseCode();
// process the response
if ($res instanceof EstraierPure_Response) {
if ($res->save_heads) {
$res->set_heads($req->getResponseHeader());
}
if ($res->save_body) {
$res->set_body($req->getResponseBody());
}
}
// }}}
}
return $code;
}
示例11: setBody
function setBody($body)
{
$this->HttpRequest->setBody($body);
}