Skip to content

Instantly share code, notes, and snippets.

@jgjay
Last active August 29, 2015 14:23
Show Gist options
  • Save jgjay/fe8c2a4cd02477687b78 to your computer and use it in GitHub Desktop.
Save jgjay/fe8c2a4cd02477687b78 to your computer and use it in GitHub Desktop.
Setting Host header with net/http
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "http://httpbin.org/headers", nil)
req.Host = "gophers"
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Printf("%s\n", body)
}
{
"headers": {
"Accept-Encoding": "gzip",
"Host": "gophers",
"User-Agent": "Go 1.1 package http"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment