Requesting a GZIP'ed page and processing with

2020-03-27 01:51发布

I'd like to make a cURL request that accepts a gzip'ed page. I would then like to unzip the page and process it. I haven't been able to find any ready built examples, so I would like a quick one. Any settings that need to be adjusted, making the actual request, and decompressing the contents.

标签: php http curl gzip
2条回答
欢心
2楼-- · 2020-03-27 02:22

Question duplicated at Uncompress a gzip file from CURL, on php. It says that response can be automatically decoded using

curl_setopt($ch,CURLOPT_ENCODING, 1);
查看更多
We Are One
3楼-- · 2020-03-27 02:34

You can request a gzipped encoding with curl_setopt, like this:

curl_setopt($curl, CURLOPT_ENCODING, 'gzip'); 

You can then decompress the content with gzdecode like this:

$response = gzdecode($response);
查看更多
登录 后发表回答