示例#1
0
 /**
  * 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
0
 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());
 }
 /**
  * Gets the request body.
  * 
  * @return string
  */
 public function getBody()
 {
     return $this->_request->getBody();
 }
示例#4
0
 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
0
 /**
  * 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
0
 /**
  * Получаем данные от Яндекса в форме массива.
  *
  * @param HTTP_Request2 $resp Объект запроса
  *
  * @return array
  */
 public function getBodyArray($resp)
 {
     if ($resp == '') {
         return array();
     }
     $body = json_decode($resp->getBody(), true);
     return $body;
 }
示例#7
0
文件: solr.php 项目: nemein/openpsa
 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
0
/**
 * 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
0
 /**
  * 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
 }
 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());
 }
 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);
 }