我们使用Spring WebSocket设置了WebSocket主题,然后客户端使用Stomp.js进行订阅。如果直接连接到WebSocket服务,则工作正常;但是现在我们在WebSocket服务前面设置了Kong作为API网关,连接时需要设置头文件"Host: websocket.com"。但是Stomp.js无法正常工作。
var url='http://xx.xx.xx.xx:8000/websocket/tracker';
var socket = new SockJS(url);
stompClient = Stomp.over(socket);
var thisheaders={
Host:'websocket.com'
};
stompClient.connect(thisheaders, function (frame) {
setConnected(true);
console.log('Connected: ' + frame);
stompClient.subscribe('/topic/greetings', function (greeting) {
showGreeting(JSON.parse(greeting.body).content);
});
});
有人知道如何添加头信息吗?或者说Stomp.js不支持添加头信息吗?