Zend_Http_Client and Garbled Response Body

Using Zend_Http_Client to make a simple REST GET request to a web service and the body of the response I got back was completely mangled – i.e. the characters were not even remotely readable. That’s strange I thought, and pasted the url in my browser and it came back fine. Looking at the response headers, I saw the content encoding was gzip ([Content-encoding] => gzip), which made sense as my browser would uncompress the response, while PHP would not automatically do that. Rather than trying to uncompress the response, I modified the request header to not accept gzip and it came back un-encoded and ready to use in PHP: [php] $client = new Zend_Http_Client($url); $client->setHeaders(array('Accept-encoding' => '')); $response = $client->request(); print_r($response); [/php]

Posted In: PHP, Zend Framework

Commentary

Anonymous 2011-05-27 19:50:29

thanks!