The go language adds custom http header methods when requesting http

  • 2020-05-26 09:19:16
  • OfStack

This example shows how the go language adds custom http header to request http. Share with you for your reference. The specific implementation method is as follows:


client := &http.Client{]
req, err := http.NewRequest("POST", "http://example.com", bytes.NewReader(postData))
req.Header.Add("User-Agent", "myClient")
resp, err := client.Do(req)
defer resp.Body.Close()

I hope this article has been helpful to your programming of Go language.


Related articles: