本文整理汇总了PHP中Zend\Http\Client::setCookies方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setCookies方法的具体用法?PHP Client::setCookies怎么用?PHP Client::setCookies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Client
的用法示例。
在下文中一共展示了Client::setCookies方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetCookieStringArray
/**
* Make sure we can set an array of string cookies
*
*/
public function testSetCookieStringArray()
{
$this->client->setUri($this->baseuri . 'testCookies.php');
$cookies = array('chocolate' => 'chips', 'crumble' => 'apple', 'another' => 'cookie');
$this->client->setCookies($cookies);
$res = $this->client->send();
$this->assertEquals($res->getBody(), serialize($cookies), 'Response body does not contain the expected cookies');
}
示例2: getNewResponse
/**
*
* @param string $url
* @return insatnce of Zend\Http\Client
*/
protected function getNewResponse($url = NULL)
{
$client = new HttpClient();
/**
* Incase of 2nd call , use product url
*/
if ($url != NULL) {
$client->setUri($url);
}
/**
* check if it is 2nd call then use the header cookies so that we can use the same session to avoid
*/
/**
* sending more traffic to the site for the performance point of view
*/
if (isset($_SESSION['cookiejar']) && $_SESSION['cookiejar'] instanceof \Zend\Http\Cookies) {
$cookieJar = $_SESSION['cookiejar'];
} else {
// set Curl Adapter
$client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
// $response = $this->getResponse ();
// keep the conntection alive for multiple calls
$client->setOptions(array('keepalive' => true));
// set content-type
// $httpResponse->getHeaders ()->addHeaderLine ( 'content-type', 'text/html; charset=utf-8' );
$client->setUri(SELF::GROCCERYURL);
$result = $client->send();
$cookieJar = \Zend\Http\Cookies::fromResponse($result, SELF::GROCCERYURL);
$_SESSION['cookiejar'] = $cookieJar;
$client->resetParameters();
return $result;
}
$connectionCookies = $cookieJar->getMatchingCookies($client->getUri());
// set the cookies for the 2nd call
$client->setCookies($this->getConntetionCookies($connectionCookies));
$response = $client->send();
return $response;
}