简体   繁体   English

如何在golang的url中为http标头中的host设置不同的值

[英]how to set different value for host in http header with host in url in golang

I can use curl to send my request successfully, but golang seems impossible to do. 我可以使用curl成功发送请求,但是golang似乎无法执行。

curl -H 'Host: aaa.com' 'http://bbb.com'

My question is: how I can send request with host which is different with host in url? 我的问题是:我该如何发送与主机请求不同的主机?

Set Request.Host to change the host header sent to the server. 设置Request.Host更改发送到服务器的主机头。

req, err := http.NewRequest("GET", "http://bbb.com/", nil)
if err != nil {
    log.Fatal(err)
}
req.Host = "aaa.com"

Playground example 操场上的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM