来自 Play Framework 的 WSClient 的 gzip 请求

gzip request from Play Framework's WSClient

我正在尝试使用 Play Framework 中的 WSClient API 调用网络服务。 主要问题是我想在不超过最大有效载荷大小的情况下传输巨大的 JSON 有效载荷(超过 2MB)。

为此,我想使用 gzip 压缩请求(使用 HTTP header Content-Encoding: gzip)。在 documentation 中提到了参数 play.ws.compressionEnabled,但它似乎只启用了 WSResponse 压缩。

我尝试手动压缩负载(使用 GZipOutputStream)并放入 header Content-Encoding:gzip,但服务器抛出 io.netty.handler.codec.compression.DecompressionException : Unsupported compression method 191 in the GZIP header.

我怎样才能正确压缩我的请求?

提前致谢

不幸的是,我不认为你可以压缩请求(底层库 Netty 不支持它)。您可以在 https://github.com/AsyncHttpClient/async-http-client/issues/93 and https://github.com/netty/netty/issues/2132

中找到更多信息