我想向我的接受请求的 WebClient
添加某种 ChannelOutboundHandler
,向其中添加“Content-Length
” header ,并转发。我知道 HttpContentEncoder 类可以做到这一点。如何在我的 WebClient
中配置此类?
最佳答案
如果您只想添加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);
关于java - 添加编解码器以在 WebClient 中的请求中添加内容长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57804509/