本文介绍了WebSocket握手期间Socket.io代码200错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

apache上的配置如下:

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/

节点在端口1337上运行

Node is running on port 1337

推荐答案

我使用springboot 2 +踩踏.就我而言,原因是在WebSocketConfig中,必须删除.withSockJS.

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()

                ;
    }

这篇关于WebSocket握手期间Socket.io代码200错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 15:15