4

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.

Neo
  • 5,070
  • 10
  • 46
  • 65

1 Answers1

4

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.

Filip Malczak
  • 3,124
  • 24
  • 44