BAEL-4698 Added HTTP Response Body as String with WebClient (#11083)

This commit is contained in:
Benjamin Caure 2021-07-29 23:14:59 +02:00 committed by GitHub
parent 5247181211
commit aee4c48bdd
2 changed files with 23 additions and 0 deletions

View File

@ -43,6 +43,12 @@
<version>${spring-boot.version}</version>
<scope>test</scope>
</dependency>
<!-- Webclient -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>${spring-boot.version}</version>
</dependency>
</dependencies>
<build>

View File

@ -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<String> body = webClient.get().retrieve().bodyToMono(String.class);
String s = body.block();
System.out.println(s);
}
}