【发布时间】:2021-11-15 20:31:55
【问题描述】:
我想从 webclient 响应中接收标头(尤其是内容类型)。 我用 flatmap-mono-getHeaders 找到了这段代码,但它不起作用。
org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'image/tiff' not supported for bodyType=org.company.MyResponse
我该如何解决?或者也许有人可以推荐一个更简单的解决方案。
Mono<Object> mono = webClient.get()
.uri(path)
.acceptCharset(StandardCharsets.UTF_8)
.retrieve()
.toEntity(MyResponse.class)
.flatMap(entity -> Mono.justOrEmpty(entity.getHeaders().getFirst("content-type")));
Object rs = mono.block();
public class MyResponse {
Object body;
Integer status;
String contentType;
}
【问题讨论】:
标签: java spring spring-boot spring-mvc spring-webflux