我希望能够从Web客户端响应中获取标题(特别是内容类型)。我找到了使用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;
}
.get().uri().retrieve()
和一些onStatus()
,我会得到一个没有.getHeaders()
的ResponseSpec
。 - user2287094HEAD
请求而不是GET
。此外,你可以使用.toBodilessEntity()
代替.toEntity(MyResponse.class)
。 - slauth.toEntity(String.class)
,我收到了头文件和图像。但是当我将字符串写入文件时,字符与真实的tif图像不同,我无法打开该文件。我还尝试使用.toEntity(MultipartFile)
,但它仍然“不支持”。也许我可以用其他名称来调用它?或者错误在字符编码中? - user2287094.toEntity(byte[].class)
。 - slauth