问题
I initialize my SockJs URL as
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);
I want to send out a request parameter , for example somesite/sockjs/info?someparam=tets"
Is it possible? Documentation of SockJs refers that options is map which can have key value but i am not sure what key to use here.
I verified URL at server which SockJs sends over and it is
http://http_backend/cecobrowsega-3.0.0.0.31/sockjs/testapp/620/4ydem52f/xhr?null
So in absence of request param its appending a null, seems there is a way to send over request param!
回答1:
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
回答2:
For those who needs code sample:
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
});
Now all the requests related to websocket will have parameter "?token=AAA"
http://localhost/ws/info?token=AAA&t=1446482506843
http://localhost/ws/515/z45wjz24/websocket?token=AAA
Tested with SockJS 1.0.3
来源:https://stackoverflow.com/questions/31118456/can-i-add-request-parameter-to-sockjs-constructor-so-that-it-can-be-send-to-serv