關於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餘嬸革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函數解壓吧。