WebSocket 握手期间出错:意外响应代码:403 [英] Error during WebSocket handshake: Unexpected response code: 403
问题描述
我已经使用 Spring Boot 应用程序 实现了 WebSockets,并且在尝试使用 chrome 扩展Smart websocket 客户端"测试 ws 连接时出现以下错误消息/强>'.但是,我在本地运行 Spring Boot 应用程序时没有问题.
I have implemented WebSockets with Spring Boot Application and have the below error message when trying to test the ws connection with the chrome extension 'Smart websocket client'. However, I have no problem when run the Spring Boot Application locally.
WebSocket connection to 'ws://192.168.X.XYZ:8080/test' failed:
Error during WebSocket handshake: Unexpected response code: 403
我看到的唯一区别在于请求标头:
The only difference which I see is in the Request headers:
在它的工作原理中 - Origin:http://192.168.X.XYZ:8080
In the one it works - Origin:http://192.168.X.XYZ:8080
在一个它不起作用 - Origin:chrome-extension://omalebghpgejjiaoknljcfmglgbpocdp
In the one it does not work - Origin:chrome-extension://omalebghpgejjiaoknljcfmglgbpocdp
我在 WebSocketConfig 类中所做的如下:
What I did in the WebSocketConfig class is below:
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(myHandler(), "/test").setAllowedOrigins("http://192.168.X.XYZ:8080");
}
并且仍然不起作用.
能否请您告知该错误的原因是什么以及如何解决?
Could you please advise what the reason for that error might be and how to fix it?
提前致谢.
推荐答案
您需要将您的 "chrome-extension://..."
origin 配置为允许的 origin 甚至 *"
,否则被服务器拒绝.
You need to configure your "chrome-extension://..."
origin as an allowed origin or even "*"
, otherwise it's rejected by the server.
这篇关于WebSocket 握手期间出错:意外响应代码:403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!