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.
You're not setting the "Content-Type"
request header, so you need to append .contentType(MediaType.APPLICATION_JSON)
to the request building part.