gpt4 book ai didi

WebSocket 握手期间的 Socket.io 代码 200 错误

转载 作者:行者123 更新时间:2023-12-02 00:45:39 24 4
gpt4 key购买 nike

我正在将 socket.io 与 nodejs 和 apache 服务器一起使用。我收到代码 200 作为响应,我知道我必须得到 101

WebSocket connection to 'wss://SITEABC.com/socket.io/?siteId=site1234567&EIO=3&transport=websocket' failed: Error during WebSocket handshake: Invalid status line

apache 上的配置如下:

RewriteCond %{HTTP:Upgrade} ^Websocket [NC]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule .* ws://localhost:1337/{REQUEST_URI} [P]

RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]

ProxyPass / http://localhost:1337/
ProxyPassReverse / http://localhost:1337/
ProxyPass /socket.io/ http://localhost:1337/socket.io/

节点在 1337 端口上运行

最佳答案

我用的是springboot 2 + stomp。就我而言,原因在 WebSocketConfig 中,必须删除 .withSockJS

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws").setAllowedOrigins("*")
.addInterceptors(new HandshakeInterceptor())

//--> important must remove,or 200 error.
//.withSockJS()

;
}

关于WebSocket 握手期间的 Socket.io 代码 200 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44059697/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com