Search code examples
spring-webfluxspring-webclient

How to make aa spring webclient request post request without body


So i want to make a post request with a body

@PostMapping("/create") public ResponseEntity create() { // returns 201 }

byt calling code has the following

 webClient.post()
                .uri(createUrl)
                .body(BodyInserters.fromValue(Mono.empty()))
                .retrieve()
                .bodyToMono(Void.class);

However i get the following message:

java.lang.IllegalArgumentException: 'body' should be an object, for reactive types use a variant specifying a publisher/producer and its related element type

How can i make a post request without a body using webclient


Solution

  • this worked.

    webClient.post()
                    .uri(url)
                    .exchange();