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

WBOY
Release: 2016-06-13 12:12:55
Original
1471 people have browsed it

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

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


Accept-Encoding:gzip,deflate,sdch


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


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

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

手册解释:

<strong><span style="background-color:rgb(255,255,255)">CURLOPT_ENCODING</span></strong> HTTP请求头中"Accept-Encoding: "的值。支持的编码有"identity""deflate""gzip"。如果为空字符串"",请求头会发送所有支持的编码类型。

只要加上这句就OK了

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template