2 回答

TA貢獻1853條經驗 獲得超18個贊
這是 http 1.1 分塊響應。該協議將發送格式:
size-of-chunk-in-hex
chunk
...
最終塊大小為 0 表示響應結束。您的示例顯示響應為 13550 字節,并以一個塊發送。

TA貢獻1873條經驗 獲得超9個贊
您正在處理分塊響應。我不確定您的最終目標是什么,但有幾種不同的選擇。消息來源本身說;
// Body represents the response body.
//
// The http Client and Transport guarantee that Body is always
// non-nil, even on responses without a body or responses with
// a zero-length body. It is the caller's responsibility to
// close Body.
//
// The Body is automatically dechunked if the server replied
// with a "chunked" Transfer-Encoding.
Body io.ReadCloser
所以例如這里; response, err := ioutil.ReadAll(resp.Body)在您中繼來自其他服務的響應的地方,您可以通過使提供的服務resp設置一個 Transfer-Encoding 標頭并使用分塊值來解決問題,假設您也可以訪問該 api。如果您只在這個中間層工作,那么您必須在編寫響應之前自己拆分響應。如果您在 Fiddler 中監控的請求沒有chunkedTransfer-Encoding,只需添加它可能會導致 Fiddler 將其顯示為與您在 Postman 中看到的相同。
- 2 回答
- 0 關注
- 182 瀏覽
添加回答
舉報