How to convert an HTTP response body to a string in Go
This article describes how you can parse the response of a web request and access it as a string in Go.
It’s often necessary to inspect the contents of an HTTP response for debugging purposes. Simply use the
ioutil.ReadAll() function to read the whole body into a slice of bytes and
convert the byte slice to a string with the string() function:
If you want to print the entire response including the headers, or only the
response headers (without the body), you may use the httputil.DumpResponse()
To exclude the response body from the output (and print only the headers),
change the boolean argument to httputil.DumpResponse from true to false.
Note that a corresponding
method exists that is just like DumpResponse, but for dumping HTTP requests instead.