问题描述

前端访问后端链接失败
在这里插入图片描述


解决方案

1.后端链接拦截放行

src/main/java/com/ruoyi/framework/config/SecurityConfig.java

.antMatchers("/websocket/**").permitAll()

参考官方文档

2.前端请求头

ruoyi后端链接是https://localhost:8090/websocket/message,因此前端链接使用wss://localhost:8090/websocket/message

  methods: {
    join() {
      const wsuri = "wss://localhost:8090/websocket/message";
      this.ws = new WebSocket(wsuri);
      }
  }
  • ws:WebSocket协议,不加密通信,与http协议对应。
  • wss:WebSocket Secure协议,加密通信,与https协议对应。

学识浅薄,文章有误之处,请多多指教。

Logo

快速构建 Web 应用程序

更多推荐