I am trying to fetch the XML feed in the compressed (gzipped) format.
Wrote the following the code. However, it still returns the feed in XML
format. It works in Java. I mean, the same service returns gzipped data
after modifying the HTTP header.

Don't know if I am doing anything wrong. Can somebody help me?

<?php

$ch = curl_init("http://abc.xyz.com/shopping.php?query=camera");

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch,CURLOPT_HEADER,0);

$headerArr = array("HTTP/1.1","Accept-Encoding: gzip;q=1.0,compress;q=0.5,identity;q=0");

curl_setopt($ch,CURLOPT_HTTPHEADER,$headerArr);

if( !($data = curl_exec ($ch)) )
echo "Cannot fetch data from the service";
else
echo $data;

curl_close ($ch);

?>

Regards,
Girish...

    One thing you could try would be adding

    curl_setopt($ch,CURLOPT_ENCODING , "gzip");

    Note that cURL would uncompress the response for you (in fact, are you sure that's not happening already? The server might be sending a compressed response after all.)

      Thanks for ur interest.....the issue is resolved.

      The apache actually reads the "user-agent" header and decide whether to compress the data before sending. Hard-coding the user-agent in the http header solved my problem.....🙂
      btw, curl doesn't decompress the data on its own.

      Girish...

        Write a Reply...