I want to add some sort of ChannelOutboundHandler
to my WebClient
that takes the request, add the 'Content-Length
' header to it, and forwards it. I know that the class HttpContentEncoder
does this. How do I configure this class in my WebClient
?
Asked
Active
Viewed 501 times
0

Prashant Pandey
- 4,332
- 3
- 26
- 44
1 Answers
0
If you just want to add Content-Length
, you do not need any handler.
You can do it like this:
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);

Violeta Georgieva
- 1,927
- 1
- 12
- 13