I'd like to ask all of you how to control gzip compression when requesting HTTP Post messages. "Accept-Encoding: gzip" as Http request headers was always added to http request I sent. But I don't want to use gzip compression. How can I manage that?
I've always used DisableCompression of transport type before executing http.NewRequest. And I already tried to set both of value true and false to DisableCompression. However it can't work well so far.
My part of code sample is as below.
//gzip
tr := &http.Transport{
DisableCompression: true,
}
//client := &http.Client{}
client := &http.Client{Transport: tr}
req, err := http.NewRequest(
"POST",
reqUrl,
bytes.NewBuffer(bytesMessage),
)
//Set Http Headers
req.Header.Add("Content-Type", "application/json; charset=UTF-8")
req.Header.Add("Accept", "*/*")
req.Header.Del("Accept-Encoding")
//HTTP request
resp, err := client.Do(req)
Go version I'm using is 1.5.
Thanks in advance.
Try
req.Header.Set("Accept-Encoding", "identity")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With