0

When I run a WebClient as follows:

WebClient.create(apiUrl)
                .get()
                .uri(uriBuilder -> uriBuilder
                        .path("/some/{productId}/")
                        .queryParam("ws_key", apiKey)
                        .build(productId)
                )
                .accept(MediaType.APPLICATION_XML)
                .retrieve()
                .bodyToMono(MyClass.class)
                .block();

The server return the header Content-Type with the value "text/html".

When I use Chrome to make the request, it returns correctly "text/xml" (it is a XML page).

I tried several "accept" parameters, and I am always getting "text/html".

Any idea on the problem? Thanks!

Mr.Eddart
  • 10,050
  • 13
  • 49
  • 77
  • Did you try to use `MediaType.TEXT_XML`? What does contain the `Accept` header in your Chrome request? – Andrei Kovrov Nov 08 '20 at 01:38
  • did you actually look into the response that you are getting xml back and that you are not getting an error msg with a html page, or something like that. – Toerktumlare Nov 08 '20 at 02:32

1 Answers1

0

Try to use curl to check it, add a -Hto setup headers.

curl http://xxx/some/product -H "Accept:text/xml"

If it got the same result(html). I think the server side should be problematic.

When using a browser to access the APIs, I think its accept header is set to "*/*, text/html" sequence or similarly by default.

If the server side is controlled by yourself, set the content type of response body explicitly.

Hantsy
  • 8,006
  • 7
  • 64
  • 109