【问题标题】:Why does the webflux client give a 404?为什么webflux客户端会报404?
【发布时间】: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


    【解决方案1】:

    WebClient 不是 WebSocket 客户端,ReactorNettyWebSocketClient(在您链接的文章中提到)是WebSocketClient。请改用这个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-25
      • 2018-12-29
      • 2016-06-18
      • 1970-01-01
      • 2012-06-29
      • 1970-01-01
      相关资源
      最近更新 更多