亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

HTTP 響應拋出錯誤 gzip: invalid header

HTTP 響應拋出錯誤 gzip: invalid header

Go
料青山看我應如是 2022-05-18 09:48:40
無法理解有什么問題。ioutil.ReadAll 應該像其他 URL 一樣使用 gzip。可通過 URL 重現:romboutskorea.co.kr錯誤:gzip:無效的標頭代碼:resp, err := http.Get("http://" + url)            if err == nil {                defer resp.Body.Close()                if resp.StatusCode == http.StatusOK {                    fmt.Printf("HTTP Response Status : %v\n", resp.StatusCode)                    bodyBytes, err := ioutil.ReadAll(resp.Body)                    if err != nil {                        fmt.Printf("HTTP Response Read error. Url: %v\n", url)                        log.Fatal(err)                    }                    bodyString := string(bodyBytes)                    fmt.Printf("HTTP Response Content Length : %v\n", len(bodyString))                }            }
查看完整描述

2 回答

?
PIPIONE

TA貢獻1829條經驗 獲得超9個贊

本站的回復是錯誤的。它聲稱使用 gzip 編碼,但實際上并沒有壓縮內容。響應看起來像這樣:


HTTP/1.1 200 OK

...

Content-Encoding: gzip

...

Transfer-Encoding: chunked

Content-Type: text/html; charset=euc-kr


8000

<html>

<head>

...

“8000”來自分塊傳輸編碼,但“...”是未分塊響應正文的開頭。顯然,即使聲稱是這樣,它也沒有被壓縮。


看起來瀏覽器只是通過忽略錯誤的編碼規范來繞過這個損壞的站點。瀏覽器實際上可以解決許多損壞的問題,這些問題并沒有真正增加供應商解決這些問題的動力:(但你可以看到這curl將失?。?/p>


$ curl -v --compressed http://romboutskorea.co.kr/main/index.php?

...

< HTTP/1.1 200 OK

< ...

< Content-Encoding: gzip

< ...

< Transfer-Encoding: chunked

< Content-Type: text/html; charset=euc-kr

* Error while processing content unencoding: invalid code lengths set

* Failed writing data

* Curl_http_done: called premature == 1

* Closing connection 0

curl: (23) Error while processing content unencoding: invalid code lengths set

Python 也是如此:


$ python3 -c 'import requests; requests.get("http://romboutskorea.co.kr/main/index.php?")'

...

requests.exceptions.ContentDecodingError: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect header check'))


查看完整回答
反對 回復 2022-05-18
?
千萬里不及你

TA貢獻1784條經驗 獲得超9個贊

我懂了

Content-Type: text/html; charset=euc-kr
Content-Encoding: gzip

檢查正文內容:就像這里一樣,它可能是一個 HTTP 響應,其中正文首先用 gzip 壓縮,然后用分塊傳輸編碼進行編碼。

NewChunkedReader將需要一個,如本例所示。


查看完整回答
反對 回復 2022-05-18
  • 2 回答
  • 0 關注
  • 1058 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號