简体   繁体   English

从 Arrow(本地主机)到模拟器的 HttpRequest

[英]HttpRequest from Arrow (localhost) to emulator

I'm trying to do a httpRequest from Arrow hosted in localhost in an emulator.我正在尝试从模拟器中的本地主机中托管的 Arrow 执行 httpRequest。 Here is the code which I got from the API Docs:这是我从 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:我收到状态=0,这意味着警报显示:

Errored: 0 :错误: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.如果我在移动 Web 中运行代码或使用节点版本代码请求相同的 API,则一切正常,但使用模拟器则不行。 My firewall is down, I'm using Windows 7.我的防火墙关闭了,我使用的是 Windows 7。

是的,没错,模拟器正在访问他自己的本地主机,正确的方法是使用 http:10.0.2.2:8080 地址

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM