【发布时间】:2018-08-17 12:16:28
【问题描述】:
我正在尝试让 webflux 客户端连接到远程 websocket。有一个示例 websocket 位于https://www.websocket.org/echo.html。只需按“连接”,我的浏览器就可以在那里发出 wss 请求。然后,在我的浏览器开发人员工具栏中,我可以看到对 wss://echo.websocket.org/?encoding=text
的成功请求https://stackify.com/reactive-spring-5/ 中也提到了这个 url(那里的代码不起作用,因为“输入”没有定义)。
但是,当我尝试使用 webflux 从 spring boot 2.0.0 访问相同的 url 时,我得到一个 404:
@PostConstruct
public void run() throws URISyntaxException {
WebClient webClient = WebClient.create();
Flux<String> r =
webClient.get().uri("wss://echo.websocket.org/?encoding=text")
.retrieve()
.bodyToFlux(String.class)
.log();
r.subscribe(res -> System.out.println("ok: " + res), ex -> System.out.println(ex));
}
错误:
org.springframework.web.reactive.function.client.WebClientResponseException: ClientResponse has erroneous status code: 404 Not Found
我最好的猜测是它不适用于以“wss://”开头的网址。我可以更改代码以使请求成功吗?
【问题讨论】:
标签: reactive-programming spring-webflux