decompression gzip data with curl

前端 未结 2 650
陌清茗
陌清茗 2021-02-05 23:19

I added curl_easy_setopt(client, CURLOPT_ENCODING, \"gzip\"); to my code.

I expected curl to cause the server to send compressed data AND to decompress it

2条回答
  •  无人共我
    2021-02-06 00:01

    c++ CURL library does not compress/decompress your data. you must do it yourself.

            CURL *curl = curl_easy_init();
    
            struct curl_slist *headers=NULL;
            headers = curl_slist_append(headers, "Accept: application/json");
            headers = curl_slist_append(headers, "Content-Type: application/json");
            headers = curl_slist_append(headers, "Content-Encoding: gzip");
    
            curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers );
            curl_easy_setopt(curl, CURLOPT_ENCODING, "gzip");
            curl_easy_setopt(curl, CURLOPT_POSTFIELDS, zipped_data.data() );
            curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, zipped_data.size() );
    

提交回复
热议问题