Android Connection Refused

来源:互联网 发布:windows.old删除不掉 编辑:程序博客网 时间:2024/05/05 07:12

想通过Android调用web应用的一个servlet,

URL url = new URL("http://localhost:8089/Test1/servlet/ServletDemo");
URLConnection connection = url.openConnection();

 

一直报 localhost/127.0.0.1:8089 - Connection refused

 

很是奇怪,查了一下 原来android模拟器(simulator)把它自己作为了localhost,也就是说,代码中使用localhost或者127.0.0.1来访问,都是访问模拟器自己

 

解决方法:

cmd——》ipconfig/all——》获得本机ip——》修改URL url = new URL("http://本机ip:8089/Test1/servlet/ServletDemo");

这样  问题就解决了

转载地址:http://blog.csdn.net/applezhengxd/article/details/5577581

0 0