當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Response::getSetCookie方法代碼示例

本文整理匯總了PHP中Guzzle\Http\Message\Response::getSetCookie方法的典型用法代碼示例。如果您正苦於以下問題:PHP Response::getSetCookie方法的具體用法?PHP Response::getSetCookie怎麽用?PHP Response::getSetCookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Guzzle\Http\Message\Response的用法示例。


在下文中一共展示了Response::getSetCookie方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: createResponse

 public function createResponse(\Guzzle\Http\Message\Response $response)
 {
     $body = $response->getBody(true);
     if (preg_match('#^Response: Success\\r\\nMessage: Authentication accepted#', $body)) {
         $setCookie = $response->getSetCookie();
         if (!preg_match('#^mansession_id=\\"([a-z0-9]+)\\"#', $setCookie, $matches)) {
             throw new Exception\UnexpectedResponseException();
         }
         return new Response\AuthenticationAcceptedResponse($matches[1]);
     }
     if (preg_match('#^Response: Error\\r\\nMessage: Permission denied#', $body)) {
         return new Response\PermissionDeniedResponse();
     }
     if (preg_match('#^Response: Error\\r\\nMessage: Authentication failed#', $body)) {
         return new Response\AuthenticationFailedResponse();
     }
     throw new Exception\UnexpectedResponseException($body);
 }
開發者ID:wehup,項目名稱:asterisk-ami,代碼行數:18,代碼來源:LoginFactory.php

示例2: addCookiesFromResponse

 /**
  * {@inheritdoc}
  */
 public function addCookiesFromResponse(Response $response)
 {
     if ($cookieHeader = $response->getSetCookie()) {
         $request = $response->getRequest();
         $parser = ParserRegistry::getInstance()->getParser('cookie');
         foreach ($cookieHeader as $cookie) {
             $parsed = $request ? $parser->parseCookie($cookie, $request->getHost(), $request->getPath()) : $parser->parseCookie($cookie);
             if ($parsed) {
                 // Break up cookie v2 into multiple cookies
                 foreach ($parsed['cookies'] as $key => $value) {
                     $row = $parsed;
                     $row['name'] = $key;
                     $row['value'] = $value;
                     unset($row['cookies']);
                     $this->add(new Cookie($row));
                 }
             }
         }
     }
 }
開發者ID:idiscussforum,項目名稱:providence,代碼行數:23,代碼來源:ArrayCookieJar.php

示例3: extractCookies

 /**
  * Extracts cookies from an HTTP Response object, looking for Set-Cookie:
  * and Set-Cookie2: headers and persists them to the cookie storage.
  *
  * @param Response $response
  */
 public function extractCookies(Response $response)
 {
     if (!($cookie = $response->getSetCookie())) {
         return array();
     }
     $cookieData = array();
     foreach ($cookie as $c) {
         $cdata = self::parseCookie($c, $response->getRequest());
         //@codeCoverageIgnoreStart
         if (!$cdata) {
             continue;
         }
         //@codeCoverageIgnoreEnd
         $cookies = array();
         // Break up cookie v2 into multiple cookies
         if (count($cdata['cookies']) == 1) {
             $cdata['cookie'] = explode('=', $cdata['cookies'][0], 2);
             unset($cdata['cookies']);
             $cookies = array($cdata);
         } else {
             foreach ($cdata['cookies'] as $cookie) {
                 $row = $cdata;
                 unset($row['cookies']);
                 $row['cookie'] = explode('=', $cookie, 2);
                 $cookies[] = $row;
             }
         }
         if (count($cookies)) {
             foreach ($cookies as &$c) {
                 $this->jar->save($c);
                 $cookieData[] = $c;
             }
         }
     }
     return $cookieData;
 }
開發者ID:MicroSDHC,項目名稱:justinribeiro.com-examples,代碼行數:42,代碼來源:CookiePlugin.php

示例4: extractCookies

 /**
  * Extracts cookies from an HTTP Response object, looking for Set-Cookie:
  * and Set-Cookie2: headers and persists them to the cookie storage.
  *
  * @param Response $response
  */
 public function extractCookies(Response $response)
 {
     if (!($cookie = $response->getSetCookie())) {
         return array();
     }
     $cookieData = array();
     $parser = ParserRegistry::get('cookie');
     foreach ($cookie as $c) {
         $request = $response->getRequest();
         if ($request) {
             $cdata = $parser->parseCookie($c, $request->getHost(), $request->getPath());
         } else {
             $cdata = $parser->parseCookie($c);
         }
         //@codeCoverageIgnoreStart
         if (!$cdata) {
             continue;
         }
         //@codeCoverageIgnoreEnd
         $cookies = array();
         // Break up cookie v2 into multiple cookies
         if (count($cdata['cookies']) == 1) {
             $cdata['cookie'] = array(key($cdata['cookies']), current($cdata['cookies']));
             unset($cdata['cookies']);
             $cookies = array($cdata);
         } else {
             foreach ($cdata['cookies'] as $key => $cookie) {
                 $row = $cdata;
                 unset($row['cookies']);
                 $row['cookie'] = array($key, $cookie);
                 $cookies[] = $row;
             }
         }
         if (count($cookies)) {
             foreach ($cookies as &$c) {
                 $this->jar->save($c);
                 $cookieData[] = $c;
             }
         }
     }
     return $cookieData;
 }
開發者ID:norv,項目名稱:guzzle,代碼行數:48,代碼來源:CookiePlugin.php


注:本文中的Guzzle\Http\Message\Response::getSetCookie方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。