本文整理汇总了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);
}
示例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());
}
}
示例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());
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例9: parseQuery
/**
* @param Response $response
* @return array
*/
public static function parseQuery(Response $response)
{
$responseBody = $response->getBody();
$params = [];
parse_str($responseBody, $params);
return $params;
}
示例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'] : '';
}
示例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;
}
示例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());
}
示例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
}
示例14: getBody
public function getBody()
{
$content = parent::getBody()->getContents();
if ($content) {
$this->content = $content;
}
return $this->content;
}
示例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);
}