Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CORS request to IP not domain name

Tags:

cors

How can I make a CORS XMLHttpRequest directly to an IP address, not an domain.

For example, i load my web page from example1.org.

I try to make a CORS request to http://example2.org/, thats working. A CORS request to http://192.168.1.100 is not working. Why?

The target of the example.org DNS entry is 192.168.1.100. The fiddler2 HTTP sniffer says, that the Browser is not even making an request, to check the CORS HTTP Header sent from the server.

I've tried it with Google Chrome Version 29.0.1510.0 canary and Version 26.0.1410.64 m.

Example code for the CORS request (that code is working. I'm not on a page in the example.org origin.):

var req = new XMLHttpRequest();
req.withCredentials = false;
req.open('GET', 'http://example2.org:8088/GetMyData', true);
req.onreadystatechange = function() {
    console.log(req.responseText);
};
req.send();
like image 618
Lux Avatar asked May 21 '13 08:05

Lux


1 Answers

If you attempt at a connection to what is considered a local IP address browsers may have (or may start to have) restrictions.

Another thing that might be causing problems is if your page is on HTTPS and the IP address is not.

However, without more information it is hard to tell what the problem is here.

like image 123
Anne Avatar answered Oct 18 '22 09:10

Anne