Java 在WebClient中添加编解码器以在我的请求中添加内容长度
我想向接受请求的Java 在WebClient中添加编解码器以在我的请求中添加内容长度,java,netty,spring-webflux,reactor-netty,spring-webclient,Java,Netty,Spring Webflux,Reactor Netty,Spring Webclient,我想向接受请求的WebClient添加某种ChannelOutboundHandler,向其添加“Content Length”头,然后转发它。我知道类HttpContentEncoder就是这样做的。如何在我的WebClient中配置此类?如果您只想添加内容长度,则不需要任何处理程序。 您可以这样做: String requestBody = "something"; String response = WebClient.create() .p
WebClient
添加某种ChannelOutboundHandler
,向其添加“Content Length
”头,然后转发它。我知道类HttpContentEncoder
就是这样做的。如何在我的WebClient
中配置此类?如果您只想添加内容长度
,则不需要任何处理程序。
您可以这样做:
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);