go HTTP 客户端正在向我的客户端请求添加一个“分 block ”传输编码字段。不幸的是,我正在连接的服务不支持它,它返回时出现错误。
有没有办法禁用它?
这是我的请求代码:
// DoHTTPRequest Do a full HTTP Client Request, with timeout
func DoHTTPRequest(method, url string, body io.Reader, headers map[string]string, timeout time.Duration) (*http.Response, error) {
// Create the request
req, err := http.NewRequest(method, url, body)
if err != nil {
return nil, err
}
// Add headers
for k, v := range headers {
req.Header.Set(k, v)
}
client := &http.Client{
Timeout: timeout,
}
return client.Do(req)
}
基本上我希望这个 header 被删除。此客户端正在与 S3 对话,S3 对于发送的 header 非常敏感。
我收到这个错误:
A header you provided implies functionality that is not implemented
最佳答案
TransferEncoding
是直接在 Request 结构上的字段。如果您明确设置它,它将不会被覆盖。
req.TransferEncoding = []string{"identity"}
关于Go HTTP Client 添加服务不支持的分块编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47275291/