Go HTTP Client 添加服务不支持的分块编码

标签 go

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"}

https://golang.org/pkg/net/http/#Request

关于Go HTTP Client 添加服务不支持的分块编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47275291/

相关文章:

reflection - 在 Go 中使用反射设置 slice 索引

docker - 检查 Go 中私有(private)注册表中是否存在 docker 镜像

json - 如何在不在Golang中定义结构的情况下读取json的 "interfaces"映射?

c++ - Go和C++中指针和引用之间的逻辑区别?

go - Gin 上传文件时始终返回204

azure - azure sdk go - 容器

戈朗 : Why the following code does NOT panic with "slice index out of range" error

javascript - Golang可以只使用HTML,CSS和JS吗?没有前端框架?

go - go 中的子类型父类(super class)型

tcp - 如何在 Go 编程中将 []byte 转换为 int