本文整理汇总了PHP中HTTP_Request2::getBody方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request2::getBody方法的具体用法?PHP HTTP_Request2::getBody怎么用?PHP HTTP_Request2::getBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_Request2
的用法示例。
在下文中一共展示了HTTP_Request2::getBody方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: calculateRequestLength
/**
* Calculates length of the request body, adds proper headers
*
* @param array associative array of request headers, this method will
* add proper 'Content-Length' and 'Content-Type' headers
* to this array (or remove them if not needed)
*/
protected function calculateRequestLength(&$headers)
{
$this->requestBody = $this->request->getBody();
if (is_string($this->requestBody)) {
$this->contentLength = strlen($this->requestBody);
} elseif (is_resource($this->requestBody)) {
$stat = fstat($this->requestBody);
$this->contentLength = $stat['size'];
rewind($this->requestBody);
} else {
$this->contentLength = $this->requestBody->getLength();
$headers['content-type'] = 'multipart/form-data; boundary=' . $this->requestBody->getBoundary();
$this->requestBody->rewind();
}
if (in_array($this->request->getMethod(), self::$bodyDisallowed) || 0 == $this->contentLength) {
// No body: send a Content-Length header nonetheless (request #12900),
// but do that only for methods that require a body (bug #14740)
if (in_array($this->request->getMethod(), self::$bodyRequired)) {
$headers['content-length'] = 0;
} else {
unset($headers['content-length']);
// if the method doesn't require a body and doesn't have a
// body, don't send a Content-Type header. (request #16799)
unset($headers['content-type']);
}
} else {
if (empty($headers['content-type'])) {
$headers['content-type'] = 'application/x-www-form-urlencoded';
}
$headers['content-length'] = $this->contentLength;
}
}
示例2: testSetMultipartBody
public function testSetMultipartBody()
{
require_once 'HTTP/Request2/MultipartBody.php';
$req = new HTTP_Request2('http://www.example.com/', HTTP_Request2::METHOD_POST);
$body = new HTTP_Request2_MultipartBody(array('foo' => 'bar'), array());
$req->setBody($body);
$this->assertSame($body, $req->getBody());
}
示例3: getBody
/**
* Gets the request body.
*
* @return string
*/
public function getBody()
{
return $this->_request->getBody();
}
示例4: getBody
public function getBody()
{
if ($this->nvpRequest) {
$ret = "";
foreach ($this->postParams as $k => $v) {
if ($ret) {
$ret .= '&';
}
$ret .= sprintf("%s[%d]=%s", $k, strlen($v), $v);
}
return $ret;
} else {
return parent::getBody();
}
}
示例5: debugCall
/**
* Collect debug information on the last call.
*
* @return array
* @uses self::$client
*/
public function debugCall()
{
return array('event' => $this->client->getLastEvent(), 'url' => (string) $this->client->getUrl(), 'data' => $this->client->getBody(), 'method' => $this->client->getMethod());
}
示例6: getBodyArray
/**
* Получаем данные от Яндекса в форме массива.
*
* @param HTTP_Request2 $resp Объект запроса
*
* @return array
*/
public function getBodyArray($resp)
{
if ($resp == '') {
return array();
}
$body = json_decode($resp->getBody(), true);
return $body;
}
示例7: _send_request
private function _send_request()
{
try {
$response = $this->request->send();
} catch (Exception $e) {
debug_add("Failed to execute request " . $this->request->getUrl() . ": " . $e->getMessage(), MIDCOM_LOG_WARN);
return false;
}
$this->code = $response->getStatus();
if ($this->code != 200) {
debug_print_r($this->request->getUrl() . " returned response code {$this->code}, body:", $response->getBody());
debug_print_r('Request content:', $this->request->getBody());
return false;
}
return true;
}
示例8: TRB_detectTrackbackUrl
/**
* Attempt to auto-detect the Trackback URL of a post.
*
* @param string $url URL of post with embedded RDF for the Trackback URL
* @return mixed Trackback URL, or false on error
* Note: The RDF, if found, is only parsed using a regular expression. Using
* the XML parser may be more successful on some occassions ...
*/
function TRB_detectTrackbackUrl($url)
{
$retval = false;
$req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
$req->setHeader('User-Agent', 'Geeklog/' . VERSION);
try {
$response = $req->send();
} catch (HTTP_Request2_Exception $e) {
COM_errorLog('TRB_detectTrackbackUrl: ' . $e->getMessage());
return false;
}
$page = $req->getBody();
// search for the RDF first
$startPos = strpos($page, '<rdf:RDF ');
if ($startPos !== false) {
$endPos = strpos($page, '</rdf:RDF>', $startPos);
$endPos += strlen('</rdf:RDF>');
$rdf = substr($page, $startPos, $endPos - $startPos);
// Okay, we COULD fire up the XML parser now. But then again ...
if (preg_match('/trackback:ping="(.*)"/', $rdf, $matches) == 1) {
if (!empty($matches[1])) {
$retval = $matches[1];
}
}
}
// no luck with the RDF? try searching for a rel="trackback" link
if ($retval === false) {
// remove all linefeeds first to help the regexp below
$page = str_replace(array("\r", "\n"), '', $page);
preg_match_all("/<a[^>]*href=[\"']([^\"']*)[\"'][^>]*>(.*?)<\\/a>/i", $page, $matches);
for ($i = 0; $i < count($matches[0]); $i++) {
$link = $matches[0][$i];
if (strpos($link, 'rel="trackback"') !== false) {
$retval = $matches[1][$i];
break;
}
}
}
return $retval;
}
示例9: isDoubleCcTld
/**
* Check if the last two parts of the FQDN are whitelisted.
*
* @param string $fqdn Host to check if it is whitelisted.
*
* @access protected
* @return boolean True if the host is whitelisted
*/
protected function isDoubleCcTld($fqdn)
{
// 30 Days should be way enough
$options = array('lifeTime' => '2592000', 'automaticSerialization' => true);
$id = md5($this->doubleCcTldFile);
$cache = new Cache_Lite($options);
if ($data = $cache->get($id)) {
// Cache hit
} else {
// Cache miss
$http = new HTTP_Request2($this->doubleCcTldFile);
if (!PEAR::isError($http->send())) {
$data = $http->getBody();
}
$data = explode("\n", $data);
$data = array_flip($data);
$cache->save($data, $id);
}
// if
if (array_key_exists($fqdn, $data)) {
return true;
} else {
return false;
}
// if
}
示例10: testBug17460
public function testBug17460()
{
$req = new HTTP_Request2('http://www.example.com/', HTTP_Request2::METHOD_POST);
$req->addPostParameter('foo', 'bar')->setHeader('content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
$this->assertEquals('foo=bar', $req->getBody());
}
示例11: sendRequest
public function sendRequest(HTTP_Request2 $request)
{
$this->requests[] = array('config' => $request->getConfig(), 'url' => $request->getUrl(), 'method' => $request->getMethod(), 'headers' => $request->getHeaders(), 'auth' => $request->getAuth(), 'body' => (string) $request->getBody());
return parent::sendRequest($request);
}