我正在用 Spring WebClient 做一些测试。在以下代码中,我已将 compress 设置为 true。但是,当我检查调试日志时,我可以看到添加了“accept-encoding: gzip”标头,但正文未压缩。有什么方法可以强制压缩发布请求正文?谢谢。
HttpClient httpClient = HttpClient.create().compress(true).wiretap(true);
WebClient webClient = WebClient.builder()
.baseUrl("https://jsonplaceholder.typicode.com")
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.clientConnector(new ReactorClientHttpConnector(httpClient))
.build();
Post post = new Post();
post.setUserId(1000L);
post.setId(2000L);
post.setTitle("Reactor Netty");
StringBuffer sb = new StringBuffer();
IntStream.range(1, 1000).forEach(i -> sb.append("Spring boot webclient"));
post.setBody(sb.toString());
Post p = webClient.post().uri("/posts").syncBody(post).retrieve().bodyToMono(Post.class).block();