英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论