Websocket:意外的响应代码:302

时间:2019-12-27 10:51:10

标签: spring-boot websocket

创建websocket连接时,出现以下异常:

VM74253:149 WebSocket connection to 'wss://HerokuAppName.herokuapp.com/connect2Deploy' failed: Error during WebSocket handshake: Unexpected response code: 302

websocket的春季启动代码:

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new SocketHandler(), "/connect2Deploy");
    }
}

Sockethandler类仅具有会话详细信息,因为我只希望会话详细信息将服务器详细信息发送到UI,因此不会有任何客户端与服务器进行通信。

@Component
public class SocketHandler extends TextWebSocketHandler {

    public WebSocketSession sessions = null;

    @Override
    public void afterConnectionEstablished(WebSocketSession session) throws Exception {
        //the messages will be broadcasted to all users.
        sessions = session;
    }

    public WebSocketSession getSessions() {
        return sessions;
    }
}

但是它总是抛出error during websocket handshake,我在这里错过了什么吗?

0 个答案:

没有答案