Setting Headers in HTTP GET Requests with Go
In a Go program, you can customize the headers of an HTTP GET request using the Header field of the Request struct. The syntax to set a header is:
req.Header.Set("header-name", "value")
Example code:
client := &http.Client{} req, _ := http.NewRequest("GET", url, nil) req.Header.Set("X-My-Header", "value") res, _ := client.Do(req)
This code sets the header with the key "X-My-Header" to the value "value". You can set multiple headers by calling Set multiple times or by using the Add method.
The above is the detailed content of How to Set Custom Headers in Go's HTTP GET Requests?. For more information, please follow other related articles on the PHP Chinese website!