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


PHP Client::setCookies方法代码示例

本文整理汇总了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');
 }
开发者ID:navassouza,项目名称:zf2,代码行数:12,代码来源:CommonHttpTests.php

示例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;
 }
开发者ID:amarlehal,项目名称:sainsburyconsoleapp,代码行数:43,代码来源:JsonGeneratorPlugin.php


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