Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending cookies with react native websockets

So I'm using react native websockets but cannot figure out how i can include cookies in websockets, any suggestions?

like image 309
user525717 Avatar asked May 16 '16 03:05

user525717


1 Answers

At the moment there is no automatic way to do it. There is a third (undocumented) parameter for the WebSocket constructor to pass custom HTTP headers to the connect request.

WebSocket(url, '', {Cookie: 'key=value'});

This works on iOS, I haven't tested it on Android but the WebSocket implementation looks like it is supported there as well.

If you just need to pass a session id or auth token, it's probably easier to pass it as a GET param in the url. Relying on undocumented behavior in a rapidly changing framework can be dangerous.

like image 80
Daniel Basedow Avatar answered Oct 03 '22 19:10

Daniel Basedow