lutaoact
lutaoact

Reputation: 4429

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 -H 'Host: aaa.com' 'http://bbb.com'

My question is: how I can send request with host which is different with host in url?

Upvotes: 3

Views: 6921

Answers (1)

Thundercat
Thundercat

Reputation: 121019

Set Request.Host to change the host header sent to the server.

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

Playground example

Upvotes: 10

Related Questions