Zend_Http_Response 的 getRawBody() 和 getBody() 方法之间的区别?
您好,想知道 $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();
}
Hi wondring whats the difference between $response->getBody() and $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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
getRawBody()
按原样返回 http 响应的正文。getBody()
针对某些标头进行调整,即解压缩通过 gzip 发送的内容或缩小内容编码标头。或者分块传输编码标头。解决这些问题最简单的方法就是看代码。也是一次很棒的学习经历。为简洁起见,对代码进行了编辑。
getRawBody()
returns the body of the http response as is.getBody()
adjust for certain headers i.e. decompresses content sent with gzip or deflate content-encoding headers. Or the chunked transfer-encoding header.The simplest way figure these questions out in to simply look at the code. Also a great learning experience. Code is edited for brevity.
HTTP 主体可以以多种方式编码。
例如,它可以被分割成不同的块,每个块前面都有块大小,或者压缩:
http:// /en.wikipedia.org/wiki/Chunked_transfer_encoding
getBody() 将根据其编码类型返回已处理的 HTTP 正文。
getRawBody 将按原样返回 HTTP 正文。
The HTTP body may be encoded in various ways.
For example, it may be split in different chunks, each one preceded with the chunk size, or gzipped:
http://en.wikipedia.org/wiki/Chunked_transfer_encoding
getBody() will return a processed HTTP body, according to it's encoding type.
getRawBody will return the HTTP body as is.