简体   繁体   中英

Android Galaxy Nexus - Localhost HTTP request not working when 3G connection is on

I am having a problem making HTTP request to localhost on my Samsung Galaxy Nexus (Android version 4.0.2).

I am running a local http server on the Android phone for some research project. The idea is that an Android application communicates with this local server using HTTP methods (GET,PUT,etc).

The problem is the following:

  • When I make an HTTP request to localhost or 127.0.0.1 with the Wi-Fi turned on everything works fine and I am able to reach the server.

    • However, when I try to do the same with the Wi-Fi turned off and using a 3G connectivity I get a in the response status line: HTTP/1.1 502 Bad Gateway

    • Lastly, if I attempt to do an HTTP request to other IP (www.google.com) over 3G connectivity, the HTTP response code is 200 OK.

Another strange fact is that running the same code on a Sony Ericsson Xperia arcS does not create the problem and everything works fine.

My guess is that there is a problem with the Samsung Galaxy Nexus when I attempt to do an HTTP call to localhost using the 3G connection. However, I don't understand why with other IP addresses it works perfect.

Any suggestions or someone with a similar problem?

Thanks in advance,

因为只能通过本地网络访问本地主机,并且您必须将内容放在在线主机上,然后使用地址或IP地址访问它,例如本地网络上的本地主机IP地址为192.168.1.2,而您正尝试访问此主机使用3g来自android的地址,3g连接无法访问本地网络资源和地址,因此它会抛出, UnknownHostException或类似的东西,希望这对我们有帮助。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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