關於curl header gzip 的讀取解決方案

來源:互聯網
上載者:User
關於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函數解壓吧。
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.