2010-11-24 67 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

聽起來像是防火牆問題。我們將需要更多的信息,甚至開始幫助