I'm trying to send POST multipart request using WebClient (spring-web 5.2.9.RELEASE), but it is missing "Content-Length" header required by the API.
Is it possible to configure WebClient to include "Content-Length" header for MultipartHttpMessageWriter which using to write request with multipart/form-data media type?
I'm sending request in this way:
webClient.post().body(BodyInserters.fromMultipartData((MultiValueMap<String, HttpEntity<String>>)request)).exchange();
Create ExchangeFilterFunction like this one https://github.com/spring-projects/spring-framework/issues/26489#issuecomment-896182570 and register it, for example
WebClient webClient = WebClient.builder()
.filter(new MultipartExchangeFilterFunction())
...
.build();
Where MultipartExchangeFilterFunction implements org.springframework.web.reactive.function.client.ExchangeFilterFunction, calculates body length and creates the Content-Length header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With