
ruoyi-vue集成websocket后报错“WebSocket connection to ‘ws://localhost:8090/websocket‘ failed:”
ruoyi-vue集成websocket后报错“WebSocket connection to 'ws://localhost:8090/websocket' failed:”
·
问题描述
前端访问后端链接失败

解决方案
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协议对应。
学识浅薄,文章有误之处,请多多指教。
更多推荐
所有评论(0)