Spring Webflux Webclient | Content type headers set issue

Neo :

The way I'm setting header is below:

import org.springframework.web.reactive.function.client.WebClient;

WebClient webClient = WebClient.create();
webClient.post().uri(url)
        .headers(httpHeaders -> httpHeaders.setAll(headersMap))
        .body(BodyInserters.fromFormData(HelperMethods.mapToMultiValueMap(body))).exchange();

It works for some services and but where I'm adding custom header base of requirement I'm facing issue.

For setting content type i added following in headers in headersMap(headersMap is a Map): ("Content-Type", "application/json")

But its giving me error: "The HTTP header line ["Content-Type": "application/json"] does not conform to RFC 7230 and has been ignored"

What may be causing this ? I tried sending content type like: ("content-type", "application/json"), But the error is same.

I cannot set header in request using ".contentType()", as number of header is variable which is set dynamically in headersMap.

Filip Malczak :

You're sending form data (usually Content-Type: multipart/form-data) with content type pointing to json - send a proper JSON or change your header to appropriate for form data.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=95393&siteId=1