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


PHP Middleware::cookies方法代码示例

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


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

示例1: create

 /**
  * Creates a default handler stack that can be used by clients.
  *
  * The returned handler will wrap the provided handler or use the most
  * appropriate default handler for you system. The returned HandlerStack has
  * support for cookies, redirects, HTTP error exceptions, and preparing a body
  * before sending.
  *
  * The returned handler stack can be passed to a client in the "handler"
  * option.
  *
  * @param callable $handler HTTP handler function to use with the stack. If no
  *                          handler is provided, the best handler for your
  *                          system will be utilized.
  *
  * @return HandlerStack
  */
 public static function create(callable $handler = null)
 {
     $stack = new self($handler ?: choose_handler());
     $stack->push(Middleware::httpErrors(), 'http_errors');
     $stack->push(Middleware::redirect(), 'allow_redirects');
     $stack->push(Middleware::cookies(), 'cookies');
     $stack->push(Middleware::prepareBody(), 'prepare_body');
     return $stack;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:26,代码来源:HandlerStack.php

示例2: testAddsCookiesToRequests

 public function testAddsCookiesToRequests()
 {
     $jar = new CookieJar();
     $m = Middleware::cookies($jar);
     $h = new MockHandler([function (RequestInterface $request) {
         return new Response(200, ['Set-Cookie' => new SetCookie(['Name' => 'name', 'Value' => 'value', 'Domain' => 'foo.com'])]);
     }]);
     $f = $m($h);
     $f(new Request('GET', 'http://foo.com'), ['cookies' => $jar])->wait();
     $this->assertCount(1, $jar);
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:11,代码来源:MiddlewareTest.php

示例3: initClient

 protected function initClient()
 {
     $handlerStack = HandlerStack::create();
     /** @noinspection PhpUnusedParameterInspection */
     $handlerStack->push(Middleware::retry(function ($retries, RequestInterface $request, ResponseInterface $response = null, $error = null) {
         return $response && $response->getStatusCode() == 503;
     }, function ($retries) {
         return rand(60, 600) * 1000;
     }));
     /** @noinspection PhpUnusedParameterInspection */
     $handlerStack->push(Middleware::retry(function ($retries, RequestInterface $request, ResponseInterface $response = null, $error = null) {
         if ($retries >= self::RETRIES_COUNT) {
             return false;
         } elseif ($response && $response->getStatusCode() > 499) {
             return true;
         } elseif ($error) {
             return true;
         } else {
             return false;
         }
     }, function ($retries) {
         return (int) pow(2, $retries - 1) * 1000;
     }));
     $handlerStack->push(Middleware::cookies());
     if ($this->logger) {
         $handlerStack->push(Middleware::log($this->logger, $this->loggerFormatter));
     }
     $this->guzzle = new \GuzzleHttp\Client(array_merge(['handler' => $handlerStack, 'cookies' => true], $this->guzzleOptions));
 }
开发者ID:keboola,项目名称:gooddata-php-client,代码行数:29,代码来源:Client.php

示例4: __construct

 public function __construct($username, $password, $url = '')
 {
     $this->username = $username;
     $this->password = $password;
     if ($url && substr($url, -1) != '/') {
         $url .= '/';
     }
     $this->url = $url ?: self::URL;
     $handlerStack = HandlerStack::create();
     // Retry from maintenance, makes 5-10 hours of waiting
     /** @noinspection PhpUnusedParameterInspection */
     $handlerStack->push(Middleware::retry(function ($retries, RequestInterface $request, ResponseInterface $response = null, $error = null) {
         return $retries < self::MAINTENANCE_RETRIES_COUNT && $response && ($response->getStatusCode() == 503 || $response->getStatusCode() == 423);
     }, function ($retries) {
         return rand(60, 600) * 1000;
     }));
     // Retry for server errors
     /** @noinspection PhpUnusedParameterInspection */
     $handlerStack->push(Middleware::retry(function ($retries, RequestInterface $request, ResponseInterface $response = null, $error = null) {
         if ($retries >= self::RETRIES_COUNT) {
             return false;
         } elseif ($response && $response->getStatusCode() > 499) {
             return true;
         } elseif ($error) {
             return true;
         } else {
             return false;
         }
     }, function ($retries) {
         return (int) pow(2, $retries - 1) * 1000;
     }));
     $handlerStack->push(Middleware::cookies());
     /*if ($this->logger) {
           $handlerStack->push(Middleware::log($this->logger, $this->loggerFormatter));
       }*/
     $this->client = new \GuzzleHttp\Client(['base_uri' => $this->url, 'handler' => $handlerStack, 'auth' => [$username, $password]]);
 }
开发者ID:keboola,项目名称:gooddata-php-client,代码行数:37,代码来源:WebDav.php


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