Home > Backend Development > PHP Tutorial > 关于curl header gzip 的读取解决方法

关于curl header gzip 的读取解决方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:16:39
Original
1282 people have browsed it

关于curl header gzip 的读取
当用curl取有些压缩网站的时候 又想取到头部

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$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);
Copy after login


取回来的内容是:
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余嬸革x栠Wm'$~0P;~馦M?趹g趋雄巺?0捈鐃?憿腤V㏕`??c爗笍?Ojt慧VCb?再c書鏗鄕b丆?杘F]衆?f?f肸B...

其实是头部+压缩内容,问题是我怎么才能读取压缩的内容呢,即网站返回的内容。

如果不要头部即去掉 直接curl_setopt($ch, CURLOPT_HEADER, 1); 
把取回来的内容保存到file.gz 文件就可以打开。

急啊,就剩最后20分了,谢谢回答啊。

------解决方案--------------------
要不把二进制数据用gzdecode函数解压吧。
Related labels:
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
Latest Issues
curl simulated login
From 1970-01-01 08:00:00
0
0
0
Convert cURL command line to PHP cURL code
From 1970-01-01 08:00:00
0
0
0
Convert command line cURL to PHP cURL
From 1970-01-01 08:00:00
0
0
0
How to set boolean value true in php curl
From 1970-01-01 08:00:00
0
0
0
Please tell me, php curl request page shows blank
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template