【发布时间】:2018-07-11 05:12:22
【问题描述】:
目前我遇到了新的 Spring 5 WebClient 的问题,我需要一些帮助来解决它。 问题是:
我请求一些返回内容类型为 text/html;charset=utf-8 的 json 响应的 url。
但不幸的是,我仍然遇到异常: org.springframework.web.reactive.function.UnsupportedMediaTypeException: 不支持内容类型“text/html;charset=utf-8”。所以我不能 将响应转换为 DTO。
对于请求,我使用以下代码:
Flux<SomeDTO> response = WebClient.create("https://someUrl")
.get()
.uri("/someUri").accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToFlux(SomeDTO.class);
response.subscribe(System.out::println);
顺便说一句,我在接受标头中指向哪种类型并不重要,总是返回 text/html。那么我怎样才能最终转换我的回复呢?
【问题讨论】:
-
MyClientHttpResponseDecorator(response) - 参数是 ClientHttpResponse,在地图中你得到的是 CLientResponse。这行得通吗?
-
你找到解决办法了吗?
标签: java spring reactive spring-webflux