我使用 magento 中的 zend http 客户端获取 json 文件内容。我不需要 getBody() 上的标题信息。我确实在它工作的一些主机上对其进行了测试。但是现场主持人给我带来了麻烦。
$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 } } }