小编m13*_*rok的帖子

带有文本/html 响应的反应式 WebClient GET 请求

目前我遇到了新的 Spring 5 WebClient 问题,我需要一些帮助来解决它。问题是:

我请求一些 url 返回内容类型为text/html;charset=utf-8 的json响应。

但不幸的是,我仍然遇到异常: org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'text/html;charset=utf-8' not supported。所以我无法将响应转换为 DTO。

对于请求,我使用以下代码:

Flux<SomeDTO> response = WebClient.create("https://someUrl")
                .get()
                .uri("/someUri").accept(MediaType.APPLICATION_JSON)
                .retrieve()
                .bodyToFlux(SomeDTO.class);

response.subscribe(System.out::println);
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我在接受标题中指向哪种类型并不重要,总是返回文本/html。那么我怎样才能最终转换我的回复呢?

java spring reactive spring-webflux

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

java ×1

reactive ×1

spring ×1

spring-webflux ×1