HiveBrain v1.2.0
Get Started
← Back to all entries
snippetgoCritical

How to set headers in http get request?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howheadersrequestsethttpget

Problem

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

Solution

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

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

Code Snippets

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

Context

Stack Overflow Q#12864302, score: 403

Revisions (0)

No revisions yet.