How to set headers in http get request?
Pay attention that in http.Request header "Host" can not be set via Set
method
req.Header.Set("Host", "domain.tld")
but can be set directly:
req.Host = "domain.tld"
:
req, err := http.NewRequest("GET", "http://10.0.0.1/", nil)
if err != nil {
...
}
req.Host = "domain.tld"
client := &http.Client{}
resp, err := client.Do(req)
The Header
field of the Request is public. You may do this :
req.Header.Set("name", "value")