Golang HTTP POST using HTTP/1.0

huangapple go评论86阅读模式
英文:

Golang HTTP POST using HTTP/1.0

问题

使用golang可以发送HTTP/1.0的请求吗?

我尝试了以下代码:

req, _ := http.NewRequest("POST", url, buffer)
req.Proto = "HTTP/1.0"
client := &http.Client{}
resp, err = client.Do(req)

但是似乎req.Proto被忽略了,请求仍然使用HTTP/1.1发送出去。

英文:

Is it possible to send HTTP requests using HTTP/1.0 with golang?

I tried the following:

req, _ := http.NewRequest("POST", url, buffer)
req.Proto = "HTTP/1.0"
client := &http.Client{}
resp, err = client.Do(req)

But it seems req.Proto is ignored. The message is sent out using HTTP/1.1.

答案1

得分: 4

显然你不能这样做。当使用Client进行请求时,Request.Proto字段会被忽略。

引用自http.Request的文档:

// 传入请求的协议版本。
// 客户端请求始终使用HTTP/1.1。
Proto string // "HTTP/1.0"

客户端请求始终使用HTTP/1.1。

英文:

Apparently you can't. The Request.Proto field is ignored when making the request by the Client.

Quoting from the doc of http.Request:

// The protocol version for incoming requests.
// Client requests always use HTTP/1.1.
Proto      string // "HTTP/1.0"

> Client requests always use HTTP/1.1.

huangapple
  • 本文由 发表于 2015年5月21日 17:20:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/30369575.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定