我将我的SockJs URL初始化为
var protocols = ['xhr-polling', 'xdr-polling', 'xdr-streaming', 'xhr-streaming'];
var options = {protocols_whitelist: protocols, debug: true,server:tets};
_ws = new SockJS(url, null, options);
我想发送一个请求参数,例如somesite / sockjs / info?someparam = tets"
有可能吗?文档of SockJs 指的是选项是map,它可以具有键值,但我不确定在这里使用什么键。
我验证了SockJs发送的服务器上的URL,它是
http://http_backend/cecobrowsega-3.0.0.0.31/sockjs/testapp/620/4ydem52f/xhr?null
因此,如果没有请求参数,它附加一个null,似乎有一种方法可以发送请求参数!
答案 0 :(得分:3)
It's available in latest sock js client. Discussion here https://github.com/sockjs/sockjs-client/issues/72
we can pass query string along with the connection URL, same syntax as for any HTTP call
答案 1 :(得分:1)
对于需要代码示例的人:
var socket = new SockJS('http://localhost/ws?token=AAA');
var stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
stompClient.subscribe('/topic/echo', function(data) {
// topic handler
});
}
}, function(err) {
// connection error
});
现在所有与websocket相关的请求都会有参数“?token = AAA”
http://localhost/ws/info?token=AAA&t=1446482506843
http://localhost/ws/515/z45wjz24/websocket?token=AAA
使用SockJS 1.0.3进行测试