Zend_Http_Client::getHeader PHP Method

getHeader() public method

Note that if the header has more than one value, an array will be returned.
public getHeader ( string $key ) : string | array | null
$key string
return string | array | null The header value or null if it is not set
    public function getHeader($key)
    {
        $key = strtolower($key);
        if (isset($this->headers[$key])) {
            return $this->headers[$key][1];
        } else {
            return null;
        }
    }

Usage Example

Example #1
0
    /**
     * 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)");
    }
All Usage Examples Of Zend_Http_Client::getHeader