本文整理汇总了PHP中REST::decodeHttpResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP REST::decodeHttpResponse方法的具体用法?PHP REST::decodeHttpResponse怎么用?PHP REST::decodeHttpResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类REST
的用法示例。
在下文中一共展示了REST::decodeHttpResponse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: makePutRequest
/**
* Sends a PUT-Request to google drive and parses the response,
* setting the appropiate variables from the response()
*
* @param Request $httpRequest the Reuqest which will be send
*
* @return false|mixed false when the upload is unfinished or the decoded http response
*
*/
private function makePutRequest(Request $httpRequest)
{
if ($this->client->getClassConfig("Request", "enable_gzip_for_uploads")) {
$httpRequest->enableGzip();
} else {
$httpRequest->disableGzip();
}
$response = $this->client->getIo()->makeRequest($httpRequest);
$response->setExpectedClass($this->request->getExpectedClass());
$code = $response->getResponseHttpCode();
$this->httpResultCode = $code;
if (308 == $code) {
// Track the amount uploaded.
$range = explode('-', $response->getResponseHeader('range'));
$this->progress = $range[1] + 1;
// Allow for changing upload URLs.
$location = $response->getResponseHeader('location');
if ($location) {
$this->resumeUri = $location;
}
// No problems, but upload not complete.
return false;
} else {
return REST::decodeHttpResponse($response, $this->client);
}
}
示例2: parseResponse
public function parseResponse(Request $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 = $this->client->getIo()->getHttpResponseHeaders($metaHeaders);
$status = substr($part, 0, strpos($part, "\n"));
$status = explode(" ", $status);
$status = $status[1];
list($partHeaders, $partBody) = $this->client->getIo()->ParseHttpResponse($part, false);
$response = new Request("");
$response->setResponseHttpCode($status);
$response->setResponseHeaders($partHeaders);
$response->setResponseBody($partBody);
// Need content id.
$key = $metaHeaders['content-id'];
if (isset($this->expected_classes[$key]) && strlen($this->expected_classes[$key]) > 0) {
$class = $this->expected_classes[$key];
$response->setExpectedClass($class);
}
try {
$response = REST::decodeHttpResponse($response, $this->client);
$responses[$key] = $response;
} catch (Exception $e) {
// Store the exception as the response, so successful responses
// can be processed.
$responses[$key] = $e;
}
}
}
return $responses;
}
return null;
}