1 回答
TA贡献2037条经验 获得超6个赞
您要求服务器发送压缩的内容 ( req.Header.Add("Accept-Encoding", "gzip, deflate")
),这就是您得到的:gzip 响应,由响应标头指示:Content-Encoding:[gzip]
。
删除该标头(不设置Accept-Encoding
请求标头),您应该得到纯 JSON 响应。或者自己解码 gzip 响应。
请注意,如果省略此标头,默认传输仍会请求gzip
编码,但也会透明地对其进行解码。由于您明确请求它,因此不会发生透明的自动解码。这在Transport.DisableCompression
现场有记录:
// DisableCompression, if true, prevents the Transport from
// requesting compression with an "Accept-Encoding: gzip"
// request header when the Request contains no existing
// Accept-Encoding value. If the Transport requests gzip on
// its own and gets a gzipped response, it's transparently
// decoded in the Response.Body. However, if the user
// explicitly requested gzip it is not automatically
// uncompressed.
DisableCompression bool
- 1 回答
- 0 关注
- 179 浏览
添加回答
举报