Mr *_*der 2 php zend-framework http response
嗨,Wondts是什么$ response-> getBody()和$ response-> getRawBody()之间的区别;
$this->_client->setUri('http://www.google.com/ig?hl=en');
try {
$response = $this->_client->request();
}catch(Zend_Http_Exception $e)
{
echo 'Zend http Client Failed';
}
echo get_class($response);
if($response->isSuccessful())
{
$response->getBody();
$response->getRawBody();
}
Run Code Online (Sandbox Code Playgroud)
getRawBody()
按原样返回http响应的主体.
getBody()
调整某些标题,即解压缩使用gzip或deflate内容编码标头发送的内容.或者分块传输编码头.
最简单的方法是将这些问题简单地看一下代码.也是一个很棒的学习经历.编译代码是为了简洁起见.
public function getRawBody()
{
return $this->body;
}
public function getBody()
{
$body = '';
// Decode the body if it was transfer-encoded
switch (strtolower($this->getHeader('transfer-encoding'))) {
case 'chunked':
// Handle chunked body
break;
// No transfer encoding, or unknown encoding extension:
default:
// return body as is
break;
}
// Decode any content-encoding (gzip or deflate) if needed
switch (strtolower($this->getHeader('content-encoding'))) {
case 'gzip':
// Handle gzip encoding
break;
case 'deflate':
// Handle deflate encoding
break;
default:
break;
}
return $body;
}
Run Code Online (Sandbox Code Playgroud)