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


PHP Response::getBody方法代码示例

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


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

示例1: cache

 public function cache(RequestInterface $request, Response $response)
 {
     $currentTime = time();
     $ttl = $request->getParams()->get('cache.override_ttl') ?: $response->getMaxAge() ?: $this->defaultTtl;
     if ($cacheControl = $response->getHeader('Cache-Control')) {
         $stale = $cacheControl->getDirective('stale-if-error');
         $ttl += $stale == true ? $ttl : $stale;
     }
     // Determine which manifest key should be used
     $key = $this->getCacheKey($request);
     $persistedRequest = $this->persistHeaders($request);
     $entries = array();
     if ($manifest = $this->cache->fetch($key)) {
         // Determine which cache entries should still be in the cache
         $vary = $response->getVary();
         foreach (unserialize($manifest) as $entry) {
             // Check if the entry is expired
             if ($entry[4] < $currentTime) {
                 continue;
             }
             $entry[1]['vary'] = isset($entry[1]['vary']) ? $entry[1]['vary'] : '';
             if ($vary != $entry[1]['vary'] || !$this->requestsMatch($vary, $entry[0], $persistedRequest)) {
                 $entries[] = $entry;
             }
         }
     }
     // Persist the response body if needed
     $bodyDigest = null;
     if ($response->getBody() && $response->getBody()->getContentLength() > 0) {
         $bodyDigest = $this->getBodyKey($request->getUrl(), $response->getBody());
         $this->cache->save($bodyDigest, (string) $response->getBody(), $ttl);
     }
     array_unshift($entries, array($persistedRequest, $this->persistHeaders($response), $response->getStatusCode(), $bodyDigest, $currentTime + $ttl));
     $this->cache->save($key, serialize($entries));
 }
开发者ID:diandianxiyu,项目名称:Yii2Api,代码行数:35,代码来源:DefaultCacheStorage.php

示例2: getDocument

 /**
  * @return \DOMDocument
  */
 public function getDocument()
 {
     $request = $this->client->get($this->url);
     $this->response = $request->send();
     $this->setHtml($this->response->getBody(true));
     return parent::getDocument();
 }
开发者ID:robmasters,项目名称:optimus,代码行数:10,代码来源:GuzzleAdapter.php

示例3: request

 /**
  * Returns object with properties int:status object:body
  * @param string $method
  * @param string $path
  * @param array $query
  * @param bool $doAuth
  * @throws \InvalidArgumentException
  * @throws \Exception
  * @return \stdClass
  */
 public function request($method, $path, $query = array(), $doAuth = false)
 {
     $this->userAgent = 'Rocker REST Client v' . Server::VERSION;
     $method = strtolower($method);
     $request = $this->initiateRequest($method, $path, $query);
     if ($doAuth) {
         $this->addAuthHeader($request);
     }
     try {
         $this->lastResponse = $request->send();
     } catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {
         $this->lastResponse = $e->getResponse();
         if ($this->lastResponse->getStatusCode() == 401 && !$doAuth && !empty($this->user)) {
             trigger_error('Doing unauthenticated requests to an URI that requires authentication (' . $path . ')', E_WARNING);
             return $this->request($method, $path, $query, true);
         }
     }
     if ($this->lastResponse->getStatusCode() == 400) {
         throw new ClientException($this->lastResponse, 400);
     }
     if ($this->lastResponse->getStatusCode() == 204) {
         return (object) array('status' => 204, 'body' => array());
     }
     if (strpos($this->lastResponse->getContentType(), 'json') === false) {
         throw new ClientException($this->lastResponse, ClientException::ERR_UNEXPECTED_CONTENT_TYPE, 'Server responded with unexpected content type (' . $this->lastResponse->getContentType() . ')');
     }
     $str = (string) $this->lastResponse->getBody();
     $body = json_decode($str);
     return (object) array('status' => $this->lastResponse->getStatusCode(), 'headers' => $this->headerCollectionToArray($this->lastResponse->getHeaders()), 'body' => $body);
 }
开发者ID:NavalKishor,项目名称:PHP-Rocker,代码行数:40,代码来源:Client.php

示例4: getBodyAsString

 /**
  * {@inheritdoc}
  */
 public function getBodyAsString()
 {
     try {
         $result = $this->response->getBody(true);
     } catch (\Exception $exception) {
         throw GuzzleRestException::createFromException($exception);
     }
     return $result;
 }
开发者ID:ramunasd,项目名称:platform,代码行数:12,代码来源:GuzzleRestResponse.php

示例5: getContent

 private function getContent(Response $response)
 {
     if ($response->isContentType('xml')) {
         return $response->xml();
     } elseif ($response->isContentType('audio')) {
         return $response->getBody()->getStream();
     } else {
         return $response->getBody();
     }
 }
开发者ID:gquemener,项目名称:7digital-client,代码行数:10,代码来源:Service.php

示例6: getResponseBody

 public function getResponseBody()
 {
     $bodyObject = $this->response->getBody();
     $bodyObject->rewind();
     $length = $bodyObject->getContentLength();
     if ($length === false || $length <= 0) {
         return "";
     }
     return $bodyObject->read($length);
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:10,代码来源:GuzzleClient.php

示例7: parseRequestFromResponse

 /**
  * @param Response $response
  * @param string $path
  * @throws UnexpectedValueException
  * @return UnifiedRequest
  */
 private function parseRequestFromResponse(Response $response, $path)
 {
     try {
         $requestInfo = Util::deserialize($response->getBody());
     } catch (UnexpectedValueException $e) {
         throw new UnexpectedValueException(sprintf('Cannot deserialize response from "%s": "%s"', $path, $response->getBody()), null, $e);
     }
     $request = RequestFactory::getInstance()->fromMessage($requestInfo['request']);
     $params = $this->configureRequest($request, $requestInfo['server'], isset($requestInfo['enclosure']) ? $requestInfo['enclosure'] : []);
     return new UnifiedRequest($request, $params);
 }
开发者ID:internations,项目名称:http-mock,代码行数:17,代码来源:RequestCollectionFacade.php

示例8: parseRequestFromResponse

 /**
  * @param Response $response
  * @param string $path
  * @throws UnexpectedValueException
  * @return UnifiedRequest
  */
 private function parseRequestFromResponse(Response $response, $path)
 {
     // @codingStandardsIgnoreStart
     $requestInfo = @unserialize($response->getBody());
     // @codingStandardsIgnoreEnd
     if ($requestInfo === false) {
         throw new UnexpectedValueException(sprintf('Cannot deserialize response from "%s": "%s"', $path, $response->getBody()));
     }
     $request = RequestFactory::getInstance()->fromMessage($requestInfo['request']);
     $params = $this->configureRequest($request, $requestInfo['server']);
     return new UnifiedRequest($request, $params);
 }
开发者ID:colindecarlo,项目名称:http-mock,代码行数:18,代码来源:RequestCollectionFacade.php

示例9: handleError

 /**
  * @throws HttpException
  */
 protected function handleError()
 {
     $body = (string) $this->response->getBody(true);
     $code = (int) $this->response->getStatusCode();
     $content = json_decode($body);
     throw new HttpException(isset($content->message) ? $content->message : 'Request not processed.', $code);
 }
开发者ID:skaisser,项目名称:upcloud,代码行数:10,代码来源:GuzzleAdapter.php

示例10: __construct

 /**
  * @param UriInterface $uri
  * @param Response $response
  */
 public function __construct(UriInterface $uri, Response $response)
 {
     $this->uri = $uri;
     $this->response = $response;
     // we store the response manually, because otherwise it will not get serialized. It is a php://temp stream
     $this->body = $response->getBody(true);
 }
开发者ID:aigouzz,项目名称:php-spider,代码行数:11,代码来源:Resource.php

示例11: testProperlyValidatesWhenUsingContentEncoding

 public function testProperlyValidatesWhenUsingContentEncoding()
 {
     $plugin = new Md5ValidatorPlugin(true);
     $request = RequestFactory::getInstance()->create('GET', 'http://www.test.com/');
     $request->getEventDispatcher()->addSubscriber($plugin);
     // Content-MD5 is the MD5 hash of the canonical content after all
     // content-encoding has been applied.  Because cURL will automatically
     // decompress entity bodies, we need to re-compress it to calculate.
     $body = EntityBody::factory('abc');
     $body->compress();
     $hash = $body->getContentMd5();
     $body->uncompress();
     $response = new Response(200, array('Content-MD5' => $hash, 'Content-Encoding' => 'gzip'), 'abc');
     $request->dispatch('request.complete', array('response' => $response));
     $this->assertEquals('abc', $response->getBody(true));
     // Try again with an unknown encoding
     $response = new Response(200, array('Content-MD5' => $hash, 'Content-Encoding' => 'foobar'), 'abc');
     $request->dispatch('request.complete', array('response' => $response));
     // Try again with compress
     $body->compress('bzip2.compress');
     $response = new Response(200, array('Content-MD5' => $body->getContentMd5(), 'Content-Encoding' => 'compress'), 'abc');
     $request->dispatch('request.complete', array('response' => $response));
     // Try again with encoding and disabled content-encoding checks
     $request->getEventDispatcher()->removeSubscriber($plugin);
     $plugin = new Md5ValidatorPlugin(false);
     $request->getEventDispatcher()->addSubscriber($plugin);
     $request->dispatch('request.complete', array('response' => $response));
 }
开发者ID:jsnshrmn,项目名称:Suma,代码行数:28,代码来源:Md5ValidatorPluginTest.php

示例12: onRequestError

 /**
  * request error
  * @param \Guzzle\Common\Event $event
  */
 public function onRequestError(Event $event)
 {
     $this->request = $event->offsetGet('request');
     $this->response = $event->offsetGet('response');
     $body = $this->response->getBody(true);
     switch ($this->response->getStatusCode()) {
         case 400:
             $this->error400($body);
             break;
         case 520:
             $this->error520($body);
             break;
         default:
             $this->commonError($body);
             break;
     }
 }
开发者ID:cstap,项目名称:kintone-sdk-php,代码行数:21,代码来源:KintoneError.php

示例13: parseResponseIntoArray

 /**
  * Parses response into an array
  *
  * @param Response $response
  * @return array
  */
 protected function parseResponseIntoArray($response)
 {
     if (strpos($response->getContentType(), 'json') === false) {
         parse_str($response->getBody(true), $array);
         return $array;
     }
     return $response->json();
 }
开发者ID:opdavies,项目名称:nwdrupalwebsite,代码行数:14,代码来源:MeetupResponseParser.php

示例14: isSuccess

 /**
  * Should return if sending the data was successful
  *
  * @return bool
  */
 public function isSuccess()
 {
     $statuscode = $this->response->getStatusCode();
     if (!in_array($statuscode, ['200', '204'])) {
         throw new \Exception('HTTP Code ' . $statuscode . ' ' . $this->response->getBody());
     }
     return true;
 }
开发者ID:undera,项目名称:influxdb-php,代码行数:13,代码来源:Guzzle.php

示例15: getResponseBody

 /**
  * {@inheritdoc}
  */
 public function getResponseBody()
 {
     if (null === $this->response) {
         return array();
     }
     $body = json_decode($this->response->getBody(true), true);
     return is_array($body) ? $body : array();
 }
开发者ID:mremi,项目名称:flowdock,代码行数:11,代码来源:BaseMessage.php


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