1

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.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140

1 Answers1

1

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

  • the error status and the lack of searchable message make me struggle with that problem. but this helped me out http://stackoverflow.com/questions/5495534/java-net-connectexception-localhost-127-0-0-18080-connection-refused – PedroTNascimento Oct 11 '16 at 22:02