Javascript websocket client adding cookie to header
Asked Answered
C

1

6

I am creating a websocket upgrade request in javascript and need to add a cookie for adding an authentication token, is this possible with cross domain restrictions? My implementation is pretty basic:

document.cookie="token="+authToken+";domain=www.test.com;path=/";
websocket = new WebSocket(endpoint);
Christen answered 15/7, 2015 at 0:11 Comment(0)
A
1

You should change the way how you set the cookies value. There is no way to add the domain and path values of the cookies, they are added automatically. You should add just the nameOfProperty and valueOfProperty. See the simple example below:

 document.cookie = "FirstProperty=FirstPropertyValue";
 document.cookie = "SecondProperty=SecondPropertyValue";

 const ws = new WebSocket('ws://localhost:2427/health');
Attenuate answered 15/9, 2017 at 18:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.