我刚接触Webclient,正在本地试用。
我在尝试命中所做的端点时遇到此错误,
org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/octet-stream' not supported for bodyType=MonoResponseDto
at org.springframework.web.reactive.function.BodyExtractors.lambda$readWithMessageReaders$12(BodyExtractors.java:201) ~[spring-webflux-5.3.25.jar:5.3.25]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
*__checkpoint ⇢ Body from GET http://localhost:7000/v2/consent [DefaultClientResponse]
下面是我的代码,用于命中端点
String url = "http://localhost:7000/v2/consent";
Mono<MonoResponseDto> response = webClient
.get()
.uri(url)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(MonoResponseDto.class);
我还尝试将Object更改为String
Mono<String> response = webClient
.get()
.uri(url)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(String.class);
回应
2023-02-06 10:27:20.342 INFO 99607 --- [nio-8012-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
{"result":"SUCCESS","data":{"createdAt":"2022-03-03T09:19:49.248Z","updatedAt":"2022-03-03T09:19:49.248Z","id":2058,"type":"Data Privacy","version":"1.3","value":"Test privacy"}}
它就像一个符咒。
我认为.accept()
不足以改变我请求的contentType。请告诉我哪里做错了。谢谢!
1条答案
按热度按时间vwkv1x7d1#
我想你的控制器出了问题。
您应该添加您制作的内容类型