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


PHP Response::getBody方法代码示例

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


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

示例1: createResponse

 /**
  * Taken from Mink\BrowserKitDriver
  *
  * @param Response $response
  *
  * @return \Symfony\Component\BrowserKit\Response
  */
 protected function createResponse(Response $response)
 {
     $contentType = $response->getHeader('Content-Type');
     $matches = null;
     if (!$contentType or strpos($contentType, 'charset=') === false) {
         $body = $response->getBody(true);
         if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
             $contentType .= ';charset=' . $matches[1];
         }
         $response->setHeader('Content-Type', $contentType);
     }
     $headers = $response->getHeaders();
     $status = $response->getStatusCode();
     $matchesMeta = null;
     $matchesHeader = null;
     $isMetaMatch = preg_match('/\\<meta[^\\>]+http-equiv="refresh" content="(\\d*)\\s*;?\\s*url=(.*?)"/i', $response->getBody(true), $matchesMeta);
     $isHeaderMatch = preg_match('~(\\d*);?url=(.*)~', (string) $response->getHeader('Refresh'), $matchesHeader);
     $matches = $isMetaMatch ? $matchesMeta : $matchesHeader;
     if (!empty($matches) && (empty($matches[1]) || $matches[1] < $this->refreshMaxInterval)) {
         $uri = $this->getAbsoluteUri($matches[2]);
         $partsUri = parse_url($uri);
         $partsCur = parse_url($this->getHistory()->current()->getUri());
         foreach ($partsCur as $key => $part) {
             if ($key === 'fragment') {
                 continue;
             }
             if (!isset($partsUri[$key]) || $partsUri[$key] !== $part) {
                 $status = 302;
                 $headers['Location'] = $uri;
                 break;
             }
         }
     }
     return new BrowserKitResponse($response->getBody(), $status, $headers);
 }
开发者ID:itillawarra,项目名称:cmfive,代码行数:42,代码来源:Guzzle.php

示例2: __construct

 /**
  * Response constructor
  *
  * @param  HttpResponse $httpResponse
  * @return self
  */
 public function __construct(HttpResponse $httpResponse)
 {
     if (stripos($httpResponse->getHeader('Content-Type'), 'text/javascript') !== false) {
         $this->_response = $this->processJson($httpResponse->getBody());
     } else {
         $this->_response = $this->processXml($httpResponse->getBody());
     }
 }
开发者ID:zimbra-api,项目名称:soap,代码行数:14,代码来源:Response.php

示例3: deduce

 /**
  * @return ErrorResponse|SuccessResponse
  */
 public function deduce()
 {
     /* @var array $response */
     $response = (array) $this->response->json();
     if (array_key_exists('type', $response) && $response['type'] === 'error') {
         return new ErrorResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
     }
     return new SuccessResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
 }
开发者ID:mahsanamin,项目名称:box-php-sdk,代码行数:12,代码来源:Response.php

示例4: getResponse

 private function getResponse(HttpResponse $httpResponse)
 {
     $response = new Response();
     if ($httpResponse->getBody()) {
         $resp = (string) $httpResponse->getBody();
         $decoded = json_decode($resp, true);
         $response->setBody($decoded);
     }
     return $response;
 }
开发者ID:EMPAT94,项目名称:Talent_Acquisition_System,代码行数:10,代码来源:GuzzleHttpClient.php

示例5: handleResponse

 protected function handleResponse(Response $response)
 {
     $code = $response->getStatusCode();
     if ($code == 200) {
         return json_decode($response->getBody()->getContents(), true);
     }
     if ($code == 401 && $this->requiresToken) {
         // Unauthorized, invalidate token
         $this->tokenStore->storeToken(null);
     }
     throw new ApiException('Request failed, received the following status: ' . $response->getStatusCode() . ' Body: ' . $response->getBody()->getContents());
 }
开发者ID:atomx,项目名称:atomx-api-php,代码行数:12,代码来源:AtomxClient.php

示例6: createResponseFromGuzzleResponse

 /**
  * @param GuzzleResponse $guzzleResponse
  *
  * @return Response
  */
 protected function createResponseFromGuzzleResponse(GuzzleResponse $guzzleResponse)
 {
     $content = null;
     if ($guzzleResponse->getBody() !== null) {
         $content = $guzzleResponse->getBody()->getContents();
     }
     $response = new Response($content, $guzzleResponse->getStatusCode());
     $response->setHeaders($guzzleResponse->getHeaders());
     $deniedHeaders = array('transfer-encoding', 'x-powered-by', 'content-length', 'content-encoding');
     foreach ($deniedHeaders as $headerName) {
         $response->removeHeader($headerName);
     }
     return $response;
 }
开发者ID:phpextra,项目名称:proxy,代码行数:19,代码来源:Guzzle4Adapter.php

示例7: parseBody

 /**
  * Parse body of response
  *
  * @return Crawler | array | string
  */
 private function parseBody()
 {
     $type = $this->getType();
     $body = (string) $this->resource->getBody();
     if (!$body) {
         return '';
     }
     if (in_array($type, ['text/html', 'text/xml'])) {
         return new Crawler($body);
     }
     if ($type === 'application/json') {
         return $this->resource->json();
     }
     return $body;
 }
开发者ID:efiku,项目名称:Scraper,代码行数:20,代码来源:Response.php

示例8: getMessages

 protected function getMessages(Response $response)
 {
     $body = (string) $response->getBody();
     if (empty($body)) {
         throw new InvalidResponseException('There was no messages returned from the server at: ' . $this->uri);
     }
     $messages = array();
     $messageCounter = 0;
     while ($body) {
         $lineLengthHex = substr($body, 0, 4);
         if (strlen($lineLengthHex) != 4) {
             throw new InvalidResponseException('A corrupt package was received from the server.  Uri: ' . $this->uri);
         }
         if ($lineLengthHex == '0000') {
             $messageCounter++;
             $body = substr_replace($body, '', 0, 4);
             continue;
         }
         $lineLength = hexdec($lineLengthHex);
         $line = substr($body, 4, $lineLength - 4);
         $body = substr_replace($body, '', 0, $lineLength);
         $messages[$messageCounter][] = trim($line);
     }
     return $messages;
 }
开发者ID:reliv,项目名称:git,代码行数:25,代码来源:Client.php

示例9: parseQuery

 /**
  * @param Response $response
  * @return array
  */
 public static function parseQuery(Response $response)
 {
     $responseBody = $response->getBody();
     $params = [];
     parse_str($responseBody, $params);
     return $params;
 }
开发者ID:assad2012,项目名称:EvaOAuth,代码行数:11,代码来源:ResponseParser.php

示例10: extractContentTypeStringOutOfMetaTag

 /**
  * @return string
  */
 protected function extractContentTypeStringOutOfMetaTag()
 {
     $matches = array();
     $body = (string) $this->response->getBody();
     @preg_match('~<meta[^>]*charset=(?<charset>[^"]*)[^>]*>~is', $body, $matches);
     return is_array($matches) && array_key_exists('charset', $matches) && $matches['charset'] != '' ? $matches['charset'] : '';
 }
开发者ID:morphodo,项目名称:crawler-bundle,代码行数:10,代码来源:DocumentBuilder.php

示例11: lastResponse

 /**
  * Returns last SOAP response.
  *
  * @return mix The last SOAP response, as an XML string.
  */
 public function lastResponse()
 {
     if ($this->response instanceof Response) {
         return $this->response->getBody();
     }
     return null;
 }
开发者ID:zimbra-api,项目名称:soap,代码行数:12,代码来源:Http.php

示例12: handleResponse

 protected function handleResponse(Response $response)
 {
     if ($response->getStatusCode() == 200) {
         return $response->getBody()->getContents();
     }
     throw new ApiException('Request failed, received the following status: ' . $response->getStatusCode() . ' Body: ' . $response->getBody()->getContents());
 }
开发者ID:erikdubbelboer,项目名称:atomx-api-php,代码行数:7,代码来源:ApiClient.php

示例13: debug

 function debug(\GuzzleHttp\Message\Response $response)
 {
     $this->dump_respuesta = 'status: ' . $response->getStatusCode() . "<br/>body: <br/>" . $response->getBody();
     //un string encodeado utf-8
     $this->dump_url = $response->getEffectiveUrl();
     //un string encodeado utf-8
 }
开发者ID:emma5021,项目名称:toba,代码行数:7,代码来源:ci_cliente_rest.php

示例14: getBody

 public function getBody()
 {
     $content = parent::getBody()->getContents();
     if ($content) {
         $this->content = $content;
     }
     return $this->content;
 }
开发者ID:alec-ascotgroup,项目名称:sendgrid-webapi-v3-php,代码行数:8,代码来源:HttpResponse.php

示例15: saveResponseToFile

 protected function saveResponseToFile(Response &$response)
 {
     $fileName = __DIR__ . '\\json\\' . sizeof($this->fileHandles) . '.json';
     $reponseSavedToFile = file_put_contents($fileName, $response->getBody());
     if ($reponseSavedToFile != false) {
         $this->fileHandles[] = $fileName;
     }
     unset($response);
 }
开发者ID:EtienneLamoureux,项目名称:durmand-scriptorium,代码行数:9,代码来源:BatchRequestManager.php


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