java.net.UnknownServiceException: CLEARTEXT communication to 127.0.0.1 not permitted by network security policy

目录
|
|
以上两个错误
现象
android虚拟机中访问电脑本地url失败
当你启动Tomcat后,在浏览器中输入http://127.0.1.1:8080/xxx.xx,你会发现你可以找打你要找的东西。但是当你在Eclipse或者android虚拟机中访问 会一直报出这样的错误:
java.net.ConnectException: failed to connect to /127.0.1.1 (port 8080)
分析
原来模拟器默认把127.0.0.1和localhost当做本身了,在模拟器上可以用10.0.2.2代替127.0.0.1和localhost,另外如果是在局域网环境可以用 192.168.0.x或者192.168.1.x(根据具体配置)连接本机,这样应该就不会报错了。
解决方法
设置访问的ip为10.0.2.2(本机的网络ip)