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
+13.6k Golang : Qt progress dialog example
+24.5k Golang : GORM read from database example
+10.4k Golang : cannot assign type int to value (type uint8) in range error
+10.6k Golang : Get local time and equivalent time in different time zone
+6.1k nginx : force all pages to be SSL
+26.9k Golang : Force your program to run with root permissions
+11.9k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+7.5k Golang : How to stop user from directly running an executable file?
+41.9k Golang : How do I convert int to uint8?
+16k Golang : Read large file with bufio.Scanner cause token too long error