WebSocket——[Error during WebSocket handshake: Unexpected response code: 403]解决方案
問題描述
WebSocket connection to 'ws://localhost:8888/MetroCity/ws/endpointChat' failed: Error during WebSocket handshake: Unexpected response code: 403?
官方文檔
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html?
問題分析
1、WebSocket 設(shè)置為不允許跨域。
2、服務(wù)器/代理服務(wù)器不支持WebSocket
解決方案
JAVA?
在registry.addEndpoint("/websocket")添加一句setAllowedOrigins("*")?
較舊版本:https://www.iteye.com/blog/mr-shang-2190758?
服務(wù)器設(shè)置
以Nginx為例?
server {listen 6340;location / {proxy_pass http://web;proxy_http_version 1.1; #Nginx在與Node后端通信時使用HTTP/1.1,是WebSockets所必需的proxy_set_header Origin '';proxy_set_header Upgrade $http_upgrade; #Nginx響應(yīng)升級請求,當(dāng)瀏覽器想要使用WebSocket時,該請求由HTTP啟動proxy_set_header Connection "Upgrade";}}參考文章
https://www.cnblogs.com/fan-gx/p/nginx.html
https://stackoverflow.com/questions/34792682/websocket-failed-error-during-websocket-handshake-unexpected-response-code-40
https://blog.csdn.net/u013269532/article/details/93476458
https://www.iteye.com/blog/mr-shang-2190758
https://blog.csdn.net/weixin_40099554/article/details/83502158
?
?
總結(jié)
以上是生活随笔為你收集整理的WebSocket——[Error during WebSocket handshake: Unexpected response code: 403]解决方案的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WebSocket——[Error du
- 下一篇: WebSocket——stomp连接错误