I'm facing some problem while sending request body in spring boot web client. Trying to send body like below:
val body = "{\n" +
"\"email\":\"[email protected]\",\n" +
"\"id\":1\n" +
"}"
val response = webClient.post()
.uri( "test_uri" )
.accept(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromObject(body))
.exchange()
.block()
Its not working. Request body should be in JSON format. Please let me know where I'm doing wrong.
In order to pass single value query parameters, create a path of the base resource URI and then use queryParam() method to append key value pairs.
In simple words, the Spring WebClient is a component that is used to make HTTP calls to other services. It is part of Spring's web reactive framework, helps building reactive and non-blocking applications. To make HTTP requests, you might have used Spring Rest Template, which was simple and always blocking web client.
You're not setting the "Content-Type"
request header, so you need to append .contentType(MediaType.APPLICATION_JSON)
to the request building part.
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