我的应用程序拒绝了这个请求,但是当我使用curl获取数据时它是有效的,所以看起来我不清楚如何在Go中压缩HTTP负载。
var buf bytes.Buffer
g := gzip.NewWriter(&buf)
g.Write([]byte("apples")
req, err := http.NewRequest("POST", q.host, bytes.NewReader(buf.Bytes()))
...
req.Header.Set("Content-Type", "text/plain")
req.Header.Set("Content-Encoding", "gzip")
resp, err := client.Do(req)
有人看到我错在哪里吗?
bytes.Reader
——它已经实现了Reader接口。 - JimBhttp.NewRequest("POST", q.host, &buf)
。 - JimB