0

ChannelOutboundHandler我想在我WebClient的请求中添加某种形式,将“ Content-Length”标头添加到它,然后转发它。我知道班级HttpContentEncoder会这样做。如何在我的WebClient?

4

1 回答 1

0

如果您只想添加Content-Length,则不需要任何处理程序。你可以这样做:

String requestBody = "something";
String response =
        WebClient.create()
                .post()
                .uri("https://postman-echo.com/post")
                .contentLength(9)
                .body(BodyInserters.fromObject(requestBody))
                .retrieve()
                .bodyToMono(String.class)
                .block();
System.out.println(response);
于 2019-09-11T14:24:20.943 回答