HTTP 响应抛出错误 gzip: invalid header

无法理解有什么问题。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))

                }

            }


料青山看我应如是
浏览 922回答 2
2回答

PIPIONE

本站的回复是错误的。它声称使用 gzip 编码,但实际上并没有压缩内容。响应看起来像这样:HTTP/1.1 200 OK...Content-Encoding: gzip...Transfer-Encoding: chunkedContent-Type: text/html; charset=euc-kr8000<html><head>...“8000”来自分块传输编码,但“...”是未分块响应正文的开头。显然,即使声称是这样,它也没有被压缩。看起来浏览器只是通过忽略错误的编码规范来绕过这个损坏的站点。浏览器实际上可以解决许多损坏的问题,这些问题并没有真正增加供应商解决这些问题的动力:(但你可以看到这curl将失败:$ 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<&nbsp;* Error while processing content unencoding: invalid code lengths set* Failed writing data* Curl_http_done: called premature == 1* Closing connection 0curl: (23) Error while processing content unencoding: invalid code lengths setPython 也是如此:$ 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'))

千万里不及你

我懂了Content-Type:&nbsp;text/html;&nbsp;charset=euc-kr Content-Encoding:&nbsp;gzip检查正文内容:就像这里一样,它可能是一个 HTTP 响应,其中正文首先用 gzip 压缩,然后用分块传输编码进行编码。NewChunkedReader将需要一个,如本例所示。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go