Home  >  Article  >  Backend Development  >  php curl采集,服务器gzip压缩返回数据怎么办

php curl采集,服务器gzip压缩返回数据怎么办

WBOY
WBOYOriginal
2016-06-23 13:42:17934browse

一般服务器不会胡乱返回gzip压缩的数据,一般是客户端请求的头部里包含你浏览器能接受的压缩方式,


Accept-Encoding:gzip,deflate,sdch


这里是gzip 、deflate、sdch这三种方式,这里不一一说明是指什么,不懂的可以去找谷哥度娘,


有些服务器强制返回gzip压缩的数据,我们采集的时候,返回的是乱码,根本无法读取使用,这个时候马上查看手册

发现其实curl里有个参数,curl_setopt($ch, CURLOPT_ENCODING,'gzip');

手册解释:

CURLOPT_ENCODING HTTP请求头中"Accept-Encoding: "的值。支持的编码有"identity","deflate"和"gzip"。如果为空字符串"",请求头会发送所有支持的编码类型。

只要加上这句就OK了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn