-
Notifications
You must be signed in to change notification settings - Fork 5k
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
CORS. Can't connect to the node #2158
Comments
The problem is definitely in web3.js. The code is: function reqListener () {
console.log(this.responseText);
};
var xmlhttp = new XMLHttpRequest(); // new HttpRequest instance
xmlhttp.onload = reqListener;
xmlhttp.open("POST", "http://<My IP>:8545/");
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttp.send(JSON.stringify( {"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1 })); It worked fine. Well... Let me see how HTTP packets differ... |
Aha. I see. It just sent the POST request directly, without any OPTIONS requests - so without any CORS support. So it looks like that web3.js and not the browser itself is trying to implement the CORS support. And it just doesn't work. |
I tried my above mentioned code with XMLHttpRequest on three browsers: Chrome, Opera, Firefox. Interestingly, Firefox crashed a few times but eventually displayed the response in Firebug lite console. I'm not sure if it is my code that is causing Firefox to crash though. So, all in all, my code is working fine, vut web3.js is not working at all. Honestly, I don't really see the purpose of web3.js then. :) |
This got fixed with PR #2564 and will be released this week. |
I'm using latest stable version of web3.js (0.20.7).
I have a private ethereum network and one node connected to it. I ran that node like this:
So the node is listening to all IP addresses on 8545 port. I set it up only for test/debug purposes.
Then I wrote a html page with web3.js v0.20.7:
I put this page on the server where ethereum node is running and requested it through the 80 port of the webserver by acceasing it from different device (smartphone).
In the firebug lite console I see "not connected" and empty json response error.
I though that something is wrong with a node and wrote a curl script:
I got the response no problem:
Then I took tcpdump and looked up what the browser actually sends to the server:
So here is the HTTP headers from dump:
So instead of POST requests the browser issuing preflight CORS requests. I looked at them closely but I still unable to understand why the browser doesn't issuing any of original post requests.
It looks like some bug of web3.js to me. But I am unable to locate it.
Any ideas?
The text was updated successfully, but these errors were encountered: