From aee4c48bdd335f4eae3738f09cbc32e8be795340 Mon Sep 17 00:00:00 2001 From: Benjamin Caure Date: Thu, 29 Jul 2021 23:14:59 +0200 Subject: [PATCH] BAEL-4698 Added HTTP Response Body as String with WebClient (#11083) --- httpclient-2/pom.xml | 6 ++++++ .../SpringWebClientUnitTest.java | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringWebClientUnitTest.java diff --git a/httpclient-2/pom.xml b/httpclient-2/pom.xml index a6b2ede900..85fc1d87e7 100644 --- a/httpclient-2/pom.xml +++ b/httpclient-2/pom.xml @@ -43,6 +43,12 @@ ${spring-boot.version} test + + + org.springframework.boot + spring-boot-starter-webflux + ${spring-boot.version} + diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringWebClientUnitTest.java b/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringWebClientUnitTest.java new file mode 100644 index 0000000000..9bd2f825ad --- /dev/null +++ b/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringWebClientUnitTest.java @@ -0,0 +1,17 @@ +package com.baeldung.httpclient.readresponsebodystring; + +import org.junit.Test; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +public class SpringWebClientUnitTest { + public static final String DUMMY_URL = "https://postman-echo.com/get"; + + @Test + public void whenUseWebClientRetrieve_thenCorrect() { + WebClient webClient = WebClient.create(DUMMY_URL); + Mono body = webClient.get().retrieve().bodyToMono(String.class); + String s = body.block(); + System.out.println(s); + } +}