当我尝试用webclient发送post请求时,出现以下错误。但是,如果我尝试用postman将请求发送到同一个uri,则会成功。请帮助我解决这个问题,因为我遇到了这个问题,而且我是spring webflux的新手。
引发异常[请求处理失败;嵌套异常为reactor.core.exceptions$reactiveexception:io.netty.channel.abstractchannel$annotatedConnectionexception:finishconnect(..)failed:拒绝连接:localhost/127.0.0.1:8080],根本原因是\n+throwable:java.net.connectexception:finishconnect(..)failed:拒绝连接\nio.netty.channel.unix.errors.throwConnectionException(错误。java:124)\n at io.netty.channel.unix.socket.finishconnect(socket。java:243)\n at io.netty.channel.epoll.abstractepollchannel$abstractepollsafsafe.dofinishconnect(abstractepollchannel。java:672)\n在io.netty.channel.epoll.abstractepollchannel$abstractepollsafsafe.finishconnect(abstractepollchannel)。java:649)\n在io.netty.channel.epoll.abstractepollchannel$abstractepollsafsafe.epollotready(abstractepollchannel。java:529)\n在
用于发送post req的我的webclient代码:
String success =
webClient
.post()
.uri("/sendRequest")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.headers(
httpHeaders -> {
httpHeaders.add(
headerName, headerValue);
})
.body(Mono.just(messageBody), String.class)
.exchange()
.flatMap(
response -> {
HttpStatus httpStatus = response.statusCode();
if (httpStatus.is2xxSuccessful()) {
System.out.println("Message posted");
} else {
System.err.println("Message FAILED. Status=" + httpStatus.toString());
}
return response.bodyToMono(String.class);
})
.block();
}
//我的webclient生成器代码:
public WebClient getWebClient() {
return WebClient.builder().baseUrl(this.MyUrl()).build();
}
暂无答案!
目前还没有任何答案,快来回答吧!