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