开发者

php curl, detect response is gzip or not

I'm using curl to fetch data from many website. Somet开发者_开发技巧imes they send back gzip. How to detect response is gzip or not?


BTW, if you set:

CURLOPT_ENCODING => '',

CURL will automatically decode the data for you.


curl_setopt($curl, CURLOPT_HEADER, true);

The result of curl_exec will then also include the headers from the HTTP response, which you can parse to see if it is gzipped.

A gzipped response would be like this:

HTTP/1.1 200 OK
Server: Apache
Content-Type: text/html
Content-Encoding: gzip
Content-Length: 26395

[GZIP COMPRESSED DATA]

So, you can first break up the response into headers and contents and then parse the headers to see if it says anything about gzip encoded content.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜