spring - Spring WebClient 连接被拒绝错误
问题描述
当我尝试使用 WebClient 发送 POST 请求时,出现以下错误。但是,如果我尝试使用邮递员将请求发送到同一个 uri,它是成功的。请帮助我解决这个问题,我陷入了这个问题我是 Spring WebFlux 的新手。
抛出异常[请求处理失败;嵌套异常是 reactor.core.Exceptions$ReactiveException: io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection denied: localhost/127.0.0.1:8080] with root cause\n+ Throwable: java.net. ConnectException:finishConnect(..) 失败:在 io.netty.channel.unix.Errors.throwConnectException(Errors.java:124) 处拒绝连接\n 在 io.netty.channel.unix.Socket.finishConnect(Socket.java :243)\n 在 io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.doFinishConnect(AbstractEpollChannel.java:672)\n 在 io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.finishConnect(AbstractEpollChannel.java:649)\ n 在 io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.epollOutReady(AbstractEpollChannel.java:529)\n 在
我的 WebClient 代码发送 Post Req:
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();
}
解决方案
推荐阅读
- azure - Powershell 工作流运行手册 - 身份验证失败
- php - 在 WooCommerce 中获取所有产品属性及其条款
- javascript - 是否可以使用 webapp 在用户的本地机器上安装和运行第三方软件?
- javascript - 使用 Express 完成后端功能后重定向
- macos - 如何在 macOS Big Sur 中使用 SwiftUI 创建状态栏图标和菜单
- vue.js - Vuejs,vuetify数据表如何在1个搜索框中进行多搜索值?
- python - Jupyter 解释器永久更改
- r - 常规图表有效,交互式显示空白
- r - 如何用 lapply() 对 R 中的一些元素求和
- java - mvn clean install 在新的本地机器上给出错误