14

So basically I want to get authentication with my websocket and the authentication required cookies, so how can I post request my cookies into websocket in js.

here is my code

var uri = 'ws://' + window.location.hostname + window.location.pathname.replace('default.htm', '') + 'chat.ashx?username=' + username;
websocket = new WebSocket(uri);

1 Answer 1

12

As mentioned here you can't actually set headers to a WebSocket() call but you can do what you are already doing, adding arguments to the URI.

Now for cookies, they should be passed along with your call check here for more info.

Sign up to request clarification or add additional context in comments.

1 Comment

[![enter image description here][1]][1] It seems when Origin === 'protocal://' + Host, Cookie will be send automatically. [1]: i.sstatic.net/2C1US.png

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.