2010-11-24 69 views
0

当我使用'localhost'或127.0.0.1从我的机器调用Web服务时,出现异常。但是,如果我提供公共IP,它可以正常工作。为什么会发生?使用IP调用Web服务的例外情况

而且,如果我使用公共IP,则无法访问Web服务。但是,如果我将相同的代码放在另一台机器上,并使用该机器的IP地址调用该Web服务,那么它工作正常。

//working fine 

url = new URL("http://192.168.50.122/NewsLetter/subscribing.php?register="+xmlString); 

//got Exception 
url = new URL("http://localhost/NewsLetter/subscribing.php?register="+xmlString); 

//got Exception 
url = new URL("http://127.0.0.1/NewsLetter/subscribing.php?register="+xmlString); 

//got Exception with my public IP - 192.168.50.117 
url = new URL("http://192.168.50.117/NewsLetter/subscribing.php?register="+xmlString); 

请帮助我......我试了很多,但无法解决它。

谢谢....

回答

2

至于本地主机而言,阅读下面的链接,如果您使用的是仿真器...

参照从模拟环境为localhost

http://developer.android.com/guide/appendix/faq/commontasks.html#localhostalias

我不知道你的其他问题,但是。

+0

这可能是。如果为主机回送接口使用特殊别名不起作用,则应该检查开发计算机上的服务是否可以从Web浏览器或该计算机上运行的任何内容访问(本机在机器上,而不在机器人内部仿真器) – 2010-11-24 08:20:37

0

听起来像是防火墙问题。我们将需要更多的信息,甚至开始帮助