Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass query parameters in react native WebSocket connection #16041

Closed
KakarN opened this issue Sep 20, 2017 · 2 comments
Closed

How to pass query parameters in react native WebSocket connection #16041

KakarN opened this issue Sep 20, 2017 · 2 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@KakarN
Copy link

KakarN commented Sep 20, 2017

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Packages: (wanted => installed)
"react": "16.0.0-alpha.12",
"react-native": "^0.47.0",

Target Platform: iOS, android

Steps to Reproduce

I have a server where I can make a WebSocket connection. When a device makes a WebSocket connection (when the app starts/splash screen), the server looks for the query parameter in the URL, which has the auth token of the user and if the token is correct, the connection is approved, else connection is rejected.

This is how the code looks on the react native client side:

const socket = new WebSocket(`ws://${website}/?token=${value}`);
socket.onmessage = (messageEvent) => {
    console.log('>>> socket on message:', messageEvent.data);
};
socket.onopen = function () {
    socket.send("hello world connection");
};
socket.onclose = () => {
    console.log('Socket disconnected');
};

This works fine in my iOS emulator, and the iOS emulator has a WebSocket connection to mine server. However, I have an android phone (testing via LAN), and when I open the app, I get an error saying:

Unable to set ws://192.xxx.xx.xx/token=aut sfiseft2sefsefs..... as default origin header

But, if I remove the query param from the URL

const socket = new WebSocket(ws://${website});

This works fine, but since I cannot pass the token in the query params, I get an error from the server.

How can I pass query parameters to the WebSocket connection in android? Am I missing something?

@hramos
Copy link
Contributor

hramos commented Sep 21, 2017

This issue looks like a question that would be best asked on StackOverflow.

StackOverflow is amazing for Q&A: it has a reputation system, voting, the ability to mark a question as answered. Because of the reputation system it is likely the community will see and answer your question there. This also helps us use the GitHub bug tracker for bugs only.

Will close this as this is really a question that should be asked on StackOverflow.

@hramos hramos closed this as completed Sep 21, 2017
@junmich
Copy link

junmich commented Nov 25, 2017

I have the same problem. Anyone have a solution? thanks

@facebook facebook locked as resolved and limited conversation to collaborators Sep 21, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Sep 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants