我正在尝试使用WebClient进行REST调用,但是我无法传递请求正文。它显示错误为-类型捕获#1-of的方法syncBody(body)未定义?
public static String getResult(Body body) {
WebClient webClient = WebClient.builder()
.defaultHeader(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON_VALUE)
.build();
String result= webClient.get()
.uri(URL)
.syncBody(body)
.retrieve()
.bodyToMono(String.class)
.block();
}
它显示错误为-类型捕获#1-of的方法syncBody(body)未定义?
最佳答案
我可能缺少某些内容,但我认为您不能使用WebClient
。实际上,在Spring Boot 2.0.5中,这甚至没有编译。
发生的情况是,当调用.get()
时,会得到不支持RequestHeadersUriSpec
或body
方法的syncBody
实例,而在调用post
(或put
等)时,会得到一个RequestBodyUriSpec
的实例
关于java - 在Spring Framework中使用WebClient进行REST调用时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57896953/