當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。