本文整理汇总了PHP中Google_HttpRequest::getResponseBody方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_HttpRequest::getResponseBody方法的具体用法?PHP Google_HttpRequest::getResponseBody怎么用?PHP Google_HttpRequest::getResponseBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google_HttpRequest
的用法示例。
在下文中一共展示了Google_HttpRequest::getResponseBody方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decodeHttpResponse
/**
* Decode an HTTP Response.
* @static
* @throws Google_ServiceException
* @param Google_HttpRequest $response The http response to be decoded.
* @return mixed|null
*/
public static function decodeHttpResponse($response)
{
$code = $response->getResponseHttpCode();
$body = $response->getResponseBody();
$decoded = null;
if (intVal($code) >= 300) {
$decoded = json_decode($body, true);
$err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl();
if ($decoded != null && isset($decoded['error']['message']) && isset($decoded['error']['code'])) {
// if we're getting a json encoded error definition, use that instead of the raw response
// body for improved readability
$err .= ": ({$decoded['error']['code']}) {$decoded['error']['message']}";
} else {
$err .= ": ({$code}) {$body}";
}
throw new Google_ServiceException($err, $code, null, $decoded['error']['errors']);
}
// Only attempt to decode the response, if the response code wasn't (204) 'no content'
if ($code != '204') {
$decoded = json_decode($body, true);
if ($decoded === null || $decoded === "") {
throw new Google_ServiceException("Invalid json in service response: {$body}");
}
}
return $decoded;
}
示例2: parseResponse
public function parseResponse(Google_HttpRequest $response)
{
$contentType = $response->getResponseHeader('content-type');
$contentType = explode(';', $contentType);
$boundary = false;
foreach ($contentType as $part) {
$part = explode('=', $part, 2);
if (isset($part[0]) && 'boundary' == trim($part[0])) {
$boundary = $part[1];
}
}
$body = $response->getResponseBody();
if ($body) {
$body = str_replace("--{$boundary}--", "--{$boundary}", $body);
$parts = explode("--{$boundary}", $body);
$responses = array();
foreach ($parts as $part) {
$part = trim($part);
if (!empty($part)) {
list($metaHeaders, $part) = explode("\r\n\r\n", $part, 2);
$metaHeaders = Google_CurlIO::parseResponseHeaders($metaHeaders);
$status = substr($part, 0, strpos($part, "\n"));
$status = explode(" ", $status);
$status = $status[1];
list($partHeaders, $partBody) = Google_CurlIO::parseHttpResponse($part, false);
$response = new Google_HttpRequest("");
$response->setResponseHttpCode($status);
$response->setResponseHeaders($partHeaders);
$response->setResponseBody($partBody);
$response = Google_REST::decodeHttpResponse($response);
// Need content id.
$responses[$metaHeaders['content-id']] = $response;
}
}
return $responses;
}
return null;
}