0

I'm able to send my request through postman just fine with the body as

"bodytext"

but when I try sending it through my webclient

String bodyStr = "bodytext";
ResponseEntity<String> response = webClient.post()
   .uri("not/actual/uri")
   .body(BodyInserters.fromValue(bodyStr))
   .retrieve()
   .toEntity(String.class)
   .block();

I get 400 status code

After an hour of searching online (couldn't find anything that helped, very little actual explanation on BodyInserters) I got it to work by changing the .body line to

.body(BodyInserters.fromValue("\"" + bodyStr + "\""))

So yeah it works now, but it looks so damn stupid that can't actually be the way it is supposed to be done can it?

0 Answers0