vankhoadesign
vankhoadesign

Reputation: 53

Zend Http Client Reponse header data?

I get json file content using the zend http client in magento. I don't need header info on getBody(). I did test it on some host where it works. But the live host gives me troubles.

$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());

Result logging:

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
    }
  }
}

Upvotes: 1

Views: 1508

Answers (1)

Javier C. H.
Javier C. H.

Reputation: 2123

Try this:

Zend_Http_Response::extractBody($response->getBody());

Or don't retrieve the headers in the request when instantiating the Zend_Http_Client:

$httpClientConfig = array(
    'maxredirects' => 0, 
    'curloptions' => array(CURLOPT_HEADER => false),
);

If the above doesn't work, you can try an alternative way of doing the request such as file_get_contents:

$response = file_get_contents($request_url);

I hope it helps.

Upvotes: 1

Related Questions