Search code examples
apiandroid-emulatortitaniumappcelerator

HttpRequest from Arrow (localhost) to emulator


I'm trying to do a httpRequest from Arrow hosted in localhost in an emulator. Here is the code which I got from the API Docs:

    var xhr = Ti.Network.createHTTPClient({
    onload: function onLoad() {
        alert("Loaded: " + this.status + ": " + this.responseText);
    },
    onerror: function onError() {
        alert("Errored: " + this.status + ": " + this.responseText);
    }
});

xhr.open("GET","http://127.0.0.1:8080/api/externa");
var authstr = 'Basic ' + Ti.Utils.base64encode('QM59cPRalcyN6eDMLqiu8HmJJ+47kLOi:');
xhr.setRequestHeader("Authorization", authstr);
xhr.send(); 

I'm receiving status=0, that means the alert shows:

Errored: 0 :

If I run the code in mobile Web or use the node version code to request the same API, everything goes fine, but with emulator it doesn't. My firewall is down, I'm using Windows 7.


Solution

  • Yes, that's correct, the emulator was acessing his own localhost, the correct way would be using the http:10.0.2.2:8080 address