Note that this parameter has been renamed CURLOPT_ACCEPT_ENCODING .
As stated in the documentation:
Sets the contents of the Accept-Encoding: header sent in the HTTP request and allows you to decode the response when the Content-Encoding header is received:
Thus, it decodes (i.e. unpacks) the response. Three encodings are supported: "identity" (does nothing), "zlib" and "gzip" . Alternatively, you can pass an empty string that creates the Accept-Encoding: header containing all supported encodings.
Finally, httpbin is convenient to test because it contains a dedicated endpoint that returns the contents of gzip. Here is an example:
#include <curl/curl.h> int main(void) { CURLcode rc; CURL *curl; curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, "http://httpbin.org/gzip"); curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "gzip"); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); rc = curl_easy_perform(curl); curl_easy_cleanup(curl); return (int) rc; }
He sends:
GET /gzip HTTP/1.1 Host: httpbin.org Accept: */* Accept-Encoding: gzip
And gets the answer:
HTTP/1.1 200 OK Access-Control-Allow-Origin: * Content-Encoding: gzip Content-Type: application/json ...
And the JSON response (thus unpacked) is written to stdout.
deltheil
source share