Sending cookies using interactive websites

So, I use interactive native websockets , but can't figure out how I can include cookies in websockets, any suggestions?

+5
source share
2 answers

There is currently no automatic way to do this. There is a third (undocumented) parameter for the WebSocket constructor to pass custom HTTP headers to the connection request.

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

This works on iOS, I have not tested it on Android, but the WebSocket implementation looks the same as there.

If you just need to pass a session identifier or an authentication token, it might be easier to pass it as a GET parameter to the URL. Drawing on undocumented behavior in a rapidly changing structure can be dangerous.

+3
source

Given React Native 0.38, this should automatically happen on Android.

Currently, there is an open PR for the fact that it automatically works on iOS, but at the moment it seems that there is some work left around testing.

At the same time, you can follow the “manual approach” suggested here :

The manual approach is to extract the cookie through the cookie manager plugin and send it as headers to the web socket.

(After you have a cookie from the manager, the way to transfer it to the website, as mentioned earlier , is to use the undocumented third parameter of WebSocket .)

0
source

All Articles