【发布时间】:2022-08-19 02:48:25
【问题描述】:
下面是我的代码:
public static void main(String[] args) {
TcpClient tcpClient = TcpClient.create()
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 100_000)
.proxy(p ->
p.type(ProxyProvider.Proxy.HTTP)
.host(\"myServerHost.com\")
.port(8080))
.doOnConnected ( connection ->
connection.addHandlerLast(new ReadTimeoutHandler(60000, TimeUnit.MILLISECONDS))
.addHandlerLast(new ReadTimeoutHandler(60000, TimeUnit.MILLISECONDS))
);
WebClient myWebClient = WebClient
.builder()
.clientConnector(new ReactorClientHttpConnector(HttpClient.from(tcpClient)))
.baseUrl(\"https://baseurl.com\")
.build();
Mono<String> rs = myWebClient.post()
.uri(\"uriForRestEndPoints\")
.header(HttpHeaders.CONTENT_TYPE.toString(), MediaType.valueOf(\"text/plain;charset=UTF-8\").toString())
.retrieve()
.bodyToMono(String.class)
.doOnEach(t -> {System.out.println(\"doOnEach: \" + t.toString()); })
.doOnSuccess(x -> { System.out.println(\"Success: \") ;})
.doOnError(x -> { System.out.println(\"Error: \") ; });
System.out.println(\"got response \"+ rs.block() + \"... \" );
}
在此示例 POC 中REST API 项目- 我得到\'非法状态异常\'因此我尝试了互联网上的所有内容。 - 喜欢超时、代理、内容标头等。
但仍然遇到同样的问题 \"java.lang.IllegalStateException:底层 HTTP 客户端完成但未发出响应。\"
还有 doOnSuccess、doOnError、doOnEach - 不打印任何东西。
谁能帮我解决这个问题。
标签: spring rest webclient illegalstateexception