HTTP headers in Websockets client API

后端 未结 11 2224
情话喂你
情话喂你 2020-11-22 10:41

Looks like it\'s easy to add custom HTTP headers to your websocket client with any HTTP header client which supports this, but I can\'t find how to do it with the JSON API.

11条回答
  •  长情又很酷
    2020-11-22 11:05

    You cannot add headers but, if you just need to pass values to the server at the moment of the connection, you can specify a query string part on the url:

    var ws = new WebSocket("ws://example.com/service?key1=value1&key2=value2");
    

    That URL is valid but - of course - you'll need to modify your server code to parse it.

提交回复
热议问题