当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Http_Client::getHeader方法代码示例

本文整理汇总了PHP中Zend_Http_Client::getHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Client::getHeader方法的具体用法?PHP Zend_Http_Client::getHeader怎么用?PHP Zend_Http_Client::getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Http_Client的用法示例。


在下文中一共展示了Zend_Http_Client::getHeader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testResetParameters

    /**
     * Make sure we can reset the parameters between consecutive requests
     *
     */
    public function testResetParameters()
    {
        $params = array(
            'quest' => 'To seek the holy grail',
            'YourMother' => 'Was a hamster',
            'specialChars' => '<>$+ &?=[]^%',
            'array' => array('firstItem', 'secondItem', '3rdItem')
        );

        $headers = array("X-Foo" => "bar");

        $this->client->setParameterPost($params);
        $this->client->setParameterGet($params);
        $this->client->setHeaders($headers);

        $res = $this->client->request('POST');

        $this->assertContains(serialize($params) . "\n" . serialize($params),
            $res->getBody(), "returned body does not contain all GET and POST parameters (it should!)");

        $this->client->resetParameters();
        $res = $this->client->request('POST');

        $this->assertNotContains(serialize($params), $res->getBody(),
            "returned body contains GET or POST parameters (it shouldn't!)");
        $this->assertContains($headers["X-Foo"], $this->client->getHeader("X-Foo"), "Header not preserved by reset");

        $this->client->resetParameters(true);
        $this->assertNull($this->client->getHeader("X-Foo"), "Header preserved by reset(true)");
    }
开发者ID:nbcutech,项目名称:o3drupal,代码行数:34,代码来源:CommonHttpTests.php

示例2: logHeaders

 /**
  * @param Zend_Http_Client $client
  *
  * @return $this
  */
 public function logHeaders(Zend_Http_Client $client)
 {
     if (!$client) {
         return $this;
     }
     $parameters = array('clickpag-access-token', 'clickpag-api-version', 'Content-Type', 'Accept');
     foreach ($parameters as $parameter) {
         $this->log($this->_helper()->__('Param: %s = %s', $parameter, $client->getHeader($parameter)));
     }
     return $this;
 }
开发者ID:marcoescudeiro,项目名称:clickpag-magento,代码行数:16,代码来源:Logger.php

示例3: testCustomHttpClientUserAgentIsNotOverridden

 /**
  * @group ZF-3288
  */
 public function testCustomHttpClientUserAgentIsNotOverridden()
 {
     $this->assertNull($this->httpClient->getHeader('user-agent'), 'UA is null if no request was made');
     $this->setServerResponseTo(true);
     $this->assertTrue($this->xmlrpcClient->call('method'));
     $this->assertSame('Zend_XmlRpc_Client', $this->httpClient->getHeader('user-agent'), 'If no custom UA is set, set Zend_XmlRpc_Client');
     $expectedUserAgent = 'Zend_XmlRpc_Client (custom)';
     $this->httpClient->setHeaders(array('user-agent' => $expectedUserAgent));
     $this->setServerResponseTo(true);
     $this->assertTrue($this->xmlrpcClient->call('method'));
     $this->assertSame($expectedUserAgent, $this->httpClient->getHeader('user-agent'));
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:15,代码来源:ClientTest.php

示例4: performHttpRequest

 /**
  * Performs a HTTP request using the specified method
  *
  * @param string $method The HTTP method for the request - 'GET', 'POST',
  *                       'PUT', 'DELETE'
  * @param string $url The URL to which this request is being performed
  * @param array $headers An associative array of HTTP headers
  *                       for this request
  * @param string $body The body of the HTTP request
  * @param string $contentType The value for the content type
  *                                of the request body
  * @param int $remainingRedirects Number of redirects to follow if request
  *                              s results in one
  * @return Zend_Http_Response The response object
  */
 public function performHttpRequest($method, $url, $headers = null, $body = null, $contentType = null, $remainingRedirects = null)
 {
     require_once 'Zend/Http/Client/Exception.php';
     if ($remainingRedirects === null) {
         $remainingRedirects = self::getMaxRedirects();
     }
     if ($headers === null) {
         $headers = array();
     }
     // Append a Gdata version header if protocol v2 or higher is in use.
     // (Protocol v1 does not use this header.)
     $major = $this->getMajorProtocolVersion();
     $minor = $this->getMinorProtocolVersion();
     if ($major >= 2) {
         $headers['GData-Version'] = $major + ($minor === null ? '.' + $minor : '');
     }
     // check the overridden method
     if (($method == 'POST' || $method == 'PUT') && $body === null && $headers['x-http-method-override'] != 'DELETE') {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify the data to post as either a ' . 'string or a child of Zend_Gdata_App_Entry');
     }
     if ($url === null) {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI to which to post.');
     }
     $headers['Content-Type'] = $contentType;
     if (Zend_Gdata_App::getGzipEnabled()) {
         // some services require the word 'gzip' to be in the user-agent
         // header in addition to the accept-encoding header
         if (strpos($this->_httpClient->getHeader('User-Agent'), 'gzip') === false) {
             $headers['User-Agent'] = $this->_httpClient->getHeader('User-Agent') . ' (gzip)';
         }
         $headers['Accept-encoding'] = 'gzip, deflate';
     } else {
         $headers['Accept-encoding'] = 'identity';
     }
     // Make sure the HTTP client object is 'clean' before making a request
     // In addition to standard headers to reset via resetParameters(),
     // also reset the Slug and If-Match headers
     $this->_httpClient->resetParameters();
     $this->_httpClient->setHeaders(array('Slug', 'If-Match'));
     // Set the params for the new request to be performed
     $this->_httpClient->setHeaders($headers);
     require_once 'Zend/Uri/Http.php';
     $uri = Zend_Uri_Http::fromString($url);
     preg_match("/^(.*?)(\\?.*)?\$/", $url, $matches);
     $this->_httpClient->setUri($matches[1]);
     $queryArray = $uri->getQueryAsArray();
     foreach ($queryArray as $name => $value) {
         $this->_httpClient->setParameterGet($name, $value);
     }
     $this->_httpClient->setConfig(array('maxredirects' => 0));
     // Set the proper adapter if we are handling a streaming upload
     $usingMimeStream = false;
     $oldHttpAdapter = null;
     if ($body instanceof Zend_Gdata_MediaMimeStream) {
         $usingMimeStream = true;
         $this->_httpClient->setRawDataStream($body, $contentType);
         $oldHttpAdapter = $this->_httpClient->getAdapter();
         if ($oldHttpAdapter instanceof Zend_Http_Client_Adapter_Proxy) {
             require_once 'Zend/Gdata/HttpAdapterStreamingProxy.php';
             $newAdapter = new Zend_Gdata_HttpAdapterStreamingProxy();
         } else {
             require_once 'Zend/Gdata/HttpAdapterStreamingSocket.php';
             $newAdapter = new Zend_Gdata_HttpAdapterStreamingSocket();
         }
         $this->_httpClient->setAdapter($newAdapter);
     } else {
         $this->_httpClient->setRawData($body, $contentType);
     }
     try {
         $response = $this->_httpClient->request($method);
         // reset adapter
         if ($usingMimeStream) {
             $this->_httpClient->setAdapter($oldHttpAdapter);
         }
     } catch (Zend_Http_Client_Exception $e) {
         // reset adapter
         if ($usingMimeStream) {
             $this->_httpClient->setAdapter($oldHttpAdapter);
         }
         require_once 'Zend/Gdata/App/HttpException.php';
         throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
     }
     if ($response->isRedirect() && $response->getStatus() != '304') {
//.........这里部分代码省略.........
开发者ID:bizanto,项目名称:Hooked,代码行数:101,代码来源:App.php

示例5: performHttpRequest

 /**
  * Performs a HTTP request using the specified method
  *
  * @param string $method The HTTP method for the request - 'GET', 'POST',
  *                       'PUT', 'DELETE'
  * @param string $url The URL to which this request is being performed
  * @param array $headers An associative array of HTTP headers
  *                       for this request
  * @param string $body The body of the HTTP request
  * @param string $contentType The value for the content type
  *                                of the request body
  * @param int $remainingRedirects Number of redirects to follow if request
  *                              s results in one
  * @return Zend_Http_Response The response object
  */
 public function performHttpRequest($method, $url, $headers = null, $body = null, $contentType = null, $remainingRedirects = null)
 {
     require_once 'Zend/Http/Client/Exception.php';
     if ($remainingRedirects === null) {
         $remainingRedirects = self::getMaxRedirects();
     }
     if ($headers === null) {
         $headers = array();
     }
     // Append a Gdata version header if protocol v2 or higher is in use.
     // (Protocol v1 does not use this header.)
     $major = $this->getMajorProtocolVersion();
     $minor = $this->getMinorProtocolVersion();
     if ($major >= 2) {
         $headers['GData-Version'] = $major + (is_null($minor) ? '.' + $minor : '');
     }
     // check the overridden method
     if (($method == 'POST' || $method == 'PUT') && $body === null && $headers['x-http-method-override'] != 'DELETE') {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify the data to post as either a ' . 'string or a child of Zend_Gdata_App_Entry');
     }
     if ($url === null) {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI to which to post.');
     }
     $headers['Content-Type'] = $contentType;
     if (Zend_Gdata_App::getGzipEnabled()) {
         // some services require the word 'gzip' to be in the user-agent header
         // in addition to the accept-encoding header
         if (strpos($this->_httpClient->getHeader('User-Agent'), 'gzip') === false) {
             $headers['User-Agent'] = $this->_httpClient->getHeader('User-Agent') . ' (gzip)';
         }
         $headers['Accept-encoding'] = 'gzip, deflate';
     } else {
         $headers['Accept-encoding'] = 'identity';
     }
     // Make sure the HTTP client object is 'clean' before making a request
     // In addition to standard headers to reset via resetParameters(),
     // also reset the Slug header
     $this->_httpClient->resetParameters();
     $this->_httpClient->setHeaders('Slug', null);
     // Set the params for the new request to be performed
     $this->_httpClient->setHeaders($headers);
     $this->_httpClient->setUri($url);
     $this->_httpClient->setConfig(array('maxredirects' => 0));
     $this->_httpClient->setRawData($body, $contentType);
     try {
         $response = $this->_httpClient->request($method);
     } catch (Zend_Http_Client_Exception $e) {
         require_once 'Zend/Gdata/App/HttpException.php';
         throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
     }
     if ($response->isRedirect() && $response->getStatus() != '304') {
         if ($remainingRedirects > 0) {
             $newUrl = $response->getHeader('Location');
             $response = $this->performHttpRequest($method, $newUrl, $headers, $body, $contentType, $remainingRedirects);
         } else {
             require_once 'Zend/Gdata/App/HttpException.php';
             throw new Zend_Gdata_App_HttpException('Number of redirects exceeds maximum', null, $response);
         }
     }
     if (!$response->isSuccessful()) {
         require_once 'Zend/Gdata/App/HttpException.php';
         $exceptionMessage = 'Expected response code 200, got ' . $response->getStatus();
         if (self::getVerboseExceptionMessages()) {
             $exceptionMessage .= "\n" . $response->getBody();
         }
         $exception = new Zend_Gdata_App_HttpException($exceptionMessage);
         $exception->setResponse($response);
         throw $exception;
     }
     return $response;
 }
开发者ID:ankuradhey,项目名称:dealtrip,代码行数:88,代码来源:App.php

示例6: testUnsetHeader

 public function testUnsetHeader()
 {
     $this->client->setHeaders('Accept-Encoding', 'gzip,deflate');
     $this->client->setHeaders('Accept-Encoding', null);
     $this->assertNull($this->client->getHeader('Accept-encoding'), 'Returned value of header is expected to be null');
 }
开发者ID:jon9872,项目名称:zend-framework,代码行数:6,代码来源:StaticTest.php

示例7: testGetHeader

 /**
  * Test we can get already set headers
  *
  */
 public function testGetHeader()
 {
     $this->_client->setHeaders(array('Accept-encoding' => 'gzip,deflate', 'Accept-language' => 'en,de,*'));
     $this->assertEquals($this->_client->getHeader('Accept-encoding'), 'gzip,deflate', 'Returned value of header is not as expected');
     $this->assertEquals($this->_client->getHeader('X-Fake-Header'), null, 'Non-existing header should not return a value');
 }
开发者ID:alab1001101,项目名称:zf2,代码行数:10,代码来源:StaticTest.php


注:本文中的Zend_Http_Client::getHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。