Socket.io code 200 Error during WebSocket handshake

萝らか妹 提交于 2019-12-31 04:45:13

问题


I am using socket.io with nodejs and an apache server over it. I am getting a code 200 as response, I know I must get 101.

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

The configuration on apache is the folowing:

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/

Node is running on port 1337


回答1:


I use springboot 2 + stomp. In my case ,the reason is in WebSocketConfig,must remove .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()

                ;
    }



回答2:


This means your requests are not being proxied to your WebSocket handler, but for some other route which returns a 200.

You should check your WebSocket handler.



来源:https://stackoverflow.com/questions/44059697/socket-io-code-200-error-during-websocket-handshake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!