java.net.ConnectException: /127.0.0.1:8080 an andr

2019-01-15 14:27发布

问题:

String url = "http://127.0.0.1:8080/SampleServlet/TestServlet?"; URL url = new URL(con_url);

run in android emualator. but i got the connectexception 02-20 13:05:08.745: ERROR/Server Connection(230): java.net.ConnectException: /127.0.0.1:8080 - Connection refused

please reply me

Thanks

回答1:

127.0.0.1 is a Android emulated device's own loopback interface.

In other words, you connect to android emulated device (not to your computer) by using 127.0.0.1.

To get connection to your machine with web-server use 10.0.2.2 or real machine IP address (if you have direct access from web).

Use command ipconfig(Windows)/ifconfig(Linux) to obtain your IP address.

Also see official docs or this!