Golang net/http/httputil.DumpRequest(), DumpResponse() and DumpRequestOut() functions example
package net/http/httputil
Golang net/http/httputil.DumpRequest() function usage example
var Req: http.Request{
Method: "POST",
URL: &url.URL{
Scheme: "http",
Host: "example.com",
Path: "/",
},
ContentLength: 6,
ProtoMajor: 1,
ProtoMinor: 1,
}
dump, err := httputil.DumpRequest(&Req, false)
or
req := &http.Request{
Method: "GET",
Host: "example.com",
URL: &url.URL{
Host: "ignored",
Scheme: "https",
Opaque: "/%2f/",
},
Header: http.Header{
"User-Agent": {"godoc-example/0.1"},
},
}
out, err := httputil.DumpRequestOut(req, true)
References :
http://golang.org/pkg/net/http/httputil/#DumpResponse
Advertisement
Something interesting
Tutorials
+12.3k Golang : Validate email address
+8.8k Golang : Executing and evaluating nested loop in html template
+19.9k Golang : Measure http.Get() execution time
+11.7k How to tell if a binary(executable) file or web application is built with Golang?
+19.7k Golang : Archive directory with tar and gzip
+15.3k nginx: [emerg] unknown directive "ssl"
+87.7k Golang : How to convert character to ASCII and back
+17k Golang : How to save log messages to file?
+16.8k Golang : Read integer from file into array
+5.4k Python : Delay with time.sleep() function example
+5.8k Golang : List all packages and search for certain package
+11.9k Golang : How to parse plain email text and process email header?