1
votes

I am having a problem. It deals with a web service using POST method with cURL. I am trying to compress the request with GZIP,DEFLATE. If you look on line three this is how it was done.

     $x = curl_init("http://url");
  curl_setopt($x, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  **curl_setopt($x, CURLOPT_ENCODING, 'Accept-Encoding: gzip,deflate');** 
  curl_setopt($x, CURLOPT_POST, 1);
  curl_setopt($x, CURLOPT_POSTFIELDS, $inputdata);
  curl_setopt($x, CURLOPT_FOLLOWLOCATION, 0);
  curl_setopt($x, CURLOPT_RETURNTRANSFER, 1);
  $data = curl_exec($x);

I get a response HTTP/1.1 200 OK Date: Mon, 22 Oct 2012 16:19:23 GMT Server: Resin/1.11.14 Content-Type: text/xml; charset=UTF-8 Vary: Accept-Encoding Content-Encoding: gzip Content-Length: 2088

However, The web service provider says that it is not compressed. What am I doing wrong?

1

1 Answers

4
votes

You don't need to put in the full header when setting CURLOPT_ENCODING, just set it to an empty string, and curl will put in the supported encodings.

curl_setopt($x, CURLOPT_ENCODING, '')