关于curl header gzip 的读取
当用curl取有些压缩网站的时候 又想取到头部
- PHP code
$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");curl_setopt($ch, CURLOPT_HEADER, 1);$content=curl_exec($ch);curl_close($ch);
取回来的内容是:
HTTP/1.1 200 OK
Date: Fri, 12 Aug 2011 07:07:59 GMT
Server: Apache
Set-Cookie: PHPSESSID=ekda6bsph83mltvna208belhj5; path=/
Expires: Fri, 12 Aug 2011 07:07:59 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Last-Modified: Fri, 12 Aug 2011 07:07:59 GMT
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 2547
Keep-Alive: timeout=300
Connection: Keep-Alive
Content-Type: text/html; charset=gb2312
秒DF胍yc余革xWm'$~0P;~M?g趋雄?0?`??c?Ojt慧VCb?再c?F]?f?fB...
其实是头部+压缩内容,问题是我怎么才能读取压缩的内容呢,即网站返回的内容。
如果不要头部即去掉 直接curl_setopt($ch, CURLOPT_HEADER, 1);
把取回来的内容保存到file.gz 文件就可以打开。
急啊,就剩最后20分了,谢谢回答啊。
[解决办法]
要不把二进制数据用gzdecode函数解压吧。