WebClient retrieving NULL as response body
Asked Answered
A

2

7

I am invoking to a service with the following code:

WebClient.create().get()
                .uri("http://www.somehost.es/api/products/1319/?ws_key=DC63ZTBVVQLN9MHQPQ9UMTL2DSW55C63")
                .retrieve()
                .bodyToMono(String.class)
                .doOnSuccess(System.out::println)
                .block();

And NULL is printed. But when I copy that URL and paste it directly int Chrome, or into Postman, the body (which is XML) is correctly returned.

Why would WebClient return null instead?

Adriannaadrianne answered 8/11, 2020 at 11:12 Comment(1)
Same problem, any takers on this? Spring Boot 2.3.4.RELEASEEnthetic
E
1

I found a reason and that the URI is encoded by default:

https://www.baeldung.com/webflux-webclient-parameters#encoding-mode

this worked for me

Enthetic answered 17/11, 2020 at 12:8 Comment(1)
did not woked for me, any other solution?Epi
A
0

in my case one Test was interfering with the others. I separate the classes and the Tests and it was ok.

Aguste answered 10/5 at 13:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.