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


PHP Response::getRequest方法代码示例

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


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

示例1: checkError

 /**
  * Check the response for an error.
  *
  * @param Response         $response The response received.
  *
  * @param RequestInterface $request  The request sent.
  *
  * @return void
  *
  * @throws \RuntimeException On any error.
  */
 protected function checkError(Response $response, RequestInterface $request)
 {
     if ($response->getStatusCode() == 200 || $response->getStatusCode() == 201) {
         return;
     }
     switch ($response->getHeader('Content-Type')) {
         case 'text/plain':
             throw new \RuntimeException('Error: ' . $response->getBody(true) . ' URI: ' . $request->getUrl());
         case 'application/json':
             $error = json_decode($response->getBody(true));
             if (isset($error->message)) {
                 throw new \RuntimeException($error->message . ' URI: ' . $request->getUrl());
             }
             break;
         default:
             throw new \RuntimeException('Unknown Error: No error message was returned from the server - Code: ' . $response->getStatusCode() . ' URI: ' . $response->getRequest()->getUrl());
     }
 }
开发者ID:cyberspectrum,项目名称:contao-toolbox,代码行数:29,代码来源:Transport.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: testSetRequest

 /**
  * @covers Guzzle\Http\Message\Response::setRequest
  */
 public function testSetRequest()
 {
     $response = new Response(200);
     $this->assertNull($response->getRequest());
     $r = new \Guzzle\Http\Message\Request('GET', 'http://www.guzzle-project.com/');
     $response->setRequest($r);
     $this->assertEquals($r, $response->getRequest());
 }
开发者ID:KANU82,项目名称:guzzle,代码行数:11,代码来源:ResponseTest.php

示例4: setResponse

 /**
  * {@inheritdoc}
  */
 public function setResponse(Response $response, $queued = false)
 {
     // Never overwrite the request associated with the response (useful for redirect history)
     if (!$response->getRequest()) {
         $response->setRequest($this);
     }
     if ($queued) {
         $this->getEventDispatcher()->addListener('request.before_send', function ($e) use($response) {
             $e['request']->setResponse($response);
         }, -9999);
     } else {
         $this->response = $response;
         // If a specific response body is specified, then use it instead of the response's body
         if ($this->responseBody && !$this->responseBody->getCustomData('default')) {
             $this->getResponseBody()->write((string) $this->response->getBody());
         } else {
             $this->responseBody = $this->response->getBody();
         }
         $this->processResponse();
     }
     return $this;
 }
开发者ID:kameshwariv,项目名称:testexample,代码行数:25,代码来源:Request.php

示例5: setResponse

 /**
  * {@inheritdoc}
  */
 public function setResponse(Response $response, $queued = false)
 {
     // Never overwrite the request associated with the response (useful for redirect history)
     if (!$response->getRequest()) {
         $response->setRequest($this);
     }
     if ($queued) {
         $this->getParams()->set('queued_response', $response);
     } else {
         $this->getParams()->remove('queued_response');
         $this->response = $response;
         $this->responseBody = $response->getBody();
         $this->processResponse();
     }
     $this->dispatch('request.set_response', $this->getEventArray());
     return $this;
 }
开发者ID:harmoniouscrab,项目名称:BSc_Project_Program,代码行数:20,代码来源:Request.php

示例6: 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

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