使用IP调用Web服务的例外情况

时间:2010-11-24 07:01:23

标签: android service

当我使用'localhost'或127.0.0.1从我的机器调用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 个答案:

答案 0 :(得分:2)

就localhost而言,如果您正在使用模拟器,请阅读以下链接...

从模拟环境中引用localhost

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

但是,我不确定你的其他问题。

答案 1 :(得分:0)

听起来像防火墙问题。我们需要更多信息才能开始提供帮助