golang http set user agent header code example
Example: golang http set user agent header
import "net/http"
req, err := http.NewRequest("GET", "http://httpbin.org/user-agent", nil)
if err != nil {
log.Fatalln(err)
}
req.Header.Set("User-Agent", "Golang_Spider_Bot/3.0")
//afetr prepear the request we should submit to http client to perform it
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatalln(err)
}