How to set headers in http get request?

wong2 picture wong2 · Oct 12, 2012 · Viewed 138.9k times · Source

I'm doing a simple http GET in Go:

client := &http.Client{}
req, _ := http.NewRequest("GET", url, nil)
res, _ := client.Do(req)

But I can't found a way to customize the request header in the doc, thanks

Answer

Denys Séguret picture Denys Séguret · Oct 12, 2012

The Header field of the Request is public. You may do this :

req.Header.Set("name", "value")