我在跨域环境中使用spring MVC ws实现WebSocket。我使用HTTP成功测试但是遇到了https的问题。
WebSocket connection to 'wss://server:port/ws/650/vmm0vcx2/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400 stomp.js:10
Whoops! Lost connection to undefined
var socket = new SockJS('wss//server:port/ws');
stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
console.log('Connected: ' + frame);
stompClient.subscribe('/topic/datafile', function(response){
var json = JSON.parse(response.body);
console.log(json);
});
});
春季配置:
<websocket:message-broker application-destination-prefix="/fieldmetrics-api">
<websocket:stomp-endpoint path="/ws" allowed-origins="*">
<websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic"/>
</websocket:message-broker>
我为servlet和过滤器设置了<async-supported>true</async-supported>
。
我是websocket的新手,请帮助。