钛XHR无法连接服务器
我试图让使用 Titan 的 Android 应用程序通过 xhr 连接本地主机,这是代码:
function e (){
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function()
{
alert(xhr.responseText);
};
xhr.onerror = function()
{
alert("Error");
};
xhr.open("GET","http://localhost/test.php");
xhr.send();}
我收到错误,这出现在进程跟踪中:
I/TiHttpClient( 211): (TiHttpClient-1) [16,27717] 发送错误 与 http://localhost 的连接被拒绝
I' trying to let android app using titanium connect the localhost via xhr, here is the code:
function e (){
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function()
{
alert(xhr.responseText);
};
xhr.onerror = function()
{
alert("Error");
};
xhr.open("GET","http://localhost/test.php");
xhr.send();}
I get an error, and this appears in the process trace:
I/TiHttpClient( 211): (TiHttpClient-1) [16,27717] Sending error
Connection to http://localhost refused
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Android 模拟器有自己的网络接口,因此 localhost 是模拟器,而不是您的主机。您需要使用IP地址10.0.2.2来访问运行模拟器的机器。请参阅http://juristr.com/blog/2009/10 /从您的主机访问主机/
the Android Emulator has its own network interface, so localhost is the emulator, not your host machine. You need to use the IP address 10.0.2.2 to access the machine that the emulator is running on. See http://juristr.com/blog/2009/10/accessing-host-machine-from-your/
尝试用你的IP打开。就像
(我用 Objective C 完成了这个,而不是用 Titanium。但你可以尝试一下)
编辑
定义端口号
Try to open with your IP. Like
(I've done this with Objective C not with Titanium. But you can give it try)
EDIT
Define Port number