Zend Http 客户端响应 header 数据?
Zend Http Client Reponse header data?
我使用 magento 中的 zend http 客户端获取 json 文件内容。
我不需要有关 getBody() 的 header 信息。我确实在它工作的一些主机上测试过它。但是直播主给我添麻烦
$request_url = "link";
$httpClientConfig = array('maxredirects' => 0);
$client = new Zend_Http_Client($request_url, $httpClientConfig);
$client->setMethod(Zend_Http_Client::GET);
try {
$response = $client->request();
} catch (Exception $e) {
Mage::throwException($this->__('Gateway request error: %s', $e->getMessage()));
}
Mage::log($response->getBody());
结果记录:
2015-01-08T09:12:46+00:00 DEBUG (7): HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 761
Connection: close
Date: Mon, 05 Jan 2015 22:53:40 GMT
Last-Modified: Sat, 15 Nov 2014 10:14:17 GMT
ETag: "a8b17a42b7ef7e5960f9bd325a8c1892"
Accept-Ranges: bytes
Server: AmazonS3
Age: 5574
X-Cache: Hit from cloudfront
Via: 1.1 522dd06c4c8acf822ccbebe21aee8d1c.cloudfront.net (CloudFront)
X-Amz-Cf-Id: c6K9QJnOESg1NERKjG-v2fX_9eskmCzz_KUYdXrOb2NSjVTbWZ_x8Q==
{
"assets": {
"standard": {
"url": "https://d3k1w8lx8mqizo.cloudfront.net/standard.png",
"infobox": {
"page1": "https://d3k1w8lx8mqizo.cloudfront.net/frontside.png",
"page2": "https://d3k1w8lx8mqizo.cloudfront.net/backside.png"
}
},
"promotion": {
"infobox": {
"page1": "https://d3k1w8lx8mqizo.cloudfront.net/frontside.png",
"page2": "https://d3k1w8lx8mqizo.cloudfront.net/backside.png"
},
"url": "https://d3k1w8lx8mqizo.cloudfront.net/standard.png",
"interest_free_months": 6,
"transaction_limit_min": 240.0
}
}
}
试试这个:
Zend_Http_Response::extractBody($response->getBody());
或者在实例化 Zend_Http_Client 时不在请求中检索 headers:
$httpClientConfig = array(
'maxredirects' => 0,
'curloptions' => array(CURLOPT_HEADER => false),
);
如果上述方法不起作用,您可以尝试其他方法来执行请求,例如 file_get_contents:
$response = file_get_contents($request_url);
希望对您有所帮助。
我使用 magento 中的 zend http 客户端获取 json 文件内容。 我不需要有关 getBody() 的 header 信息。我确实在它工作的一些主机上测试过它。但是直播主给我添麻烦
$request_url = "link";
$httpClientConfig = array('maxredirects' => 0);
$client = new Zend_Http_Client($request_url, $httpClientConfig);
$client->setMethod(Zend_Http_Client::GET);
try {
$response = $client->request();
} catch (Exception $e) {
Mage::throwException($this->__('Gateway request error: %s', $e->getMessage()));
}
Mage::log($response->getBody());
结果记录:
2015-01-08T09:12:46+00:00 DEBUG (7): HTTP/1.1 200 OK Content-Type: application/json Content-Length: 761 Connection: close Date: Mon, 05 Jan 2015 22:53:40 GMT Last-Modified: Sat, 15 Nov 2014 10:14:17 GMT ETag: "a8b17a42b7ef7e5960f9bd325a8c1892" Accept-Ranges: bytes Server: AmazonS3 Age: 5574 X-Cache: Hit from cloudfront Via: 1.1 522dd06c4c8acf822ccbebe21aee8d1c.cloudfront.net (CloudFront) X-Amz-Cf-Id: c6K9QJnOESg1NERKjG-v2fX_9eskmCzz_KUYdXrOb2NSjVTbWZ_x8Q== { "assets": { "standard": { "url": "https://d3k1w8lx8mqizo.cloudfront.net/standard.png", "infobox": { "page1": "https://d3k1w8lx8mqizo.cloudfront.net/frontside.png", "page2": "https://d3k1w8lx8mqizo.cloudfront.net/backside.png" } }, "promotion": { "infobox": { "page1": "https://d3k1w8lx8mqizo.cloudfront.net/frontside.png", "page2": "https://d3k1w8lx8mqizo.cloudfront.net/backside.png" }, "url": "https://d3k1w8lx8mqizo.cloudfront.net/standard.png", "interest_free_months": 6, "transaction_limit_min": 240.0 } } }
试试这个:
Zend_Http_Response::extractBody($response->getBody());
或者在实例化 Zend_Http_Client 时不在请求中检索 headers:
$httpClientConfig = array(
'maxredirects' => 0,
'curloptions' => array(CURLOPT_HEADER => false),
);
如果上述方法不起作用,您可以尝试其他方法来执行请求,例如 file_get_contents:
$response = file_get_contents($request_url);
希望对您有所帮助。