Golang Example for adding custom headers to a request.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"fmt" | |
"net/http" | |
"os" | |
) | |
func main() { | |
client := &http.Client{} | |
postData := make([]byte, 100) | |
req, err := http.NewRequest("POST", "http://example.com", bytes.NewReader(postData)) | |
if err != nil { | |
os.Exit(1) | |
} | |
req.Header.Add("User-Agent", "myClient") | |
resp, err := client.Do(req) | |
defer resp.Body.Close() | |
fmt.Println(resp) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is a nicer way for post data: