Golang net/http.Header type and Add, Set, Del, Get methods examples
package net/http
Golang net/http.Header type and methods usage example
Example 1:
client := &http.Client{}
req, _ := http.NewRequest("POST", postStr, nil)
req.Header.Add("Content-Type: ", "application/x-www-form-urlencoded") // create a new key
req.Header.Set("Content-Type: ", "application/x-www-form-urlencoded") // update the existing key
req.Header.Del("Content-Type: ")
str := req.Header.Get("Content-Type: ")
resp, err := client.Do(req)
Example 2:
func addHeaderHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Access-Control-Allow-Methods", "PUT")
w.Header().Add("Access-Control-Allow-Headers", "Content-Type")
}
References :
http://golang.org/pkg/net/http/#Header.Add
http://golang.org/pkg/net/http/#Header.Del
Advertisement
Something interesting
Tutorials
+6.3k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+4.9k Golang : Generate Interleaved 2 inch by 5 inch barcode
+12.7k Golang : Qt progress dialog example
+8.3k Golang : How to capture return values from goroutines?
+9.2k Golang : Eroding and dilating image with OpenCV example
+25.1k Golang : How to write CSV data to file
+49.9k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+13.8k Golang : How to get URL port?
+9.7k Golang : How to profile or log time spend on execution?
+20k Golang : Underscore or snake_case to camel case example
+20.3k Golang : Clean up null characters from input data
+7.1k Gogland : Single File versus Go Application Run Configurations