HttpHostConnectException 10.0.2.2:8080被拒绝 [英] HttpHostConnectException 10.0.2.2:8080 refused
问题描述
在执行以下语句时,该应用一分钟没有响应,然后出现以下logcat消息:
On executing the following statement the app does not respond for a minute and then following logcat message occurs :
HttpPost httpPost = new HttpPost("http://10.0.2.2:8080/webapp/CreateUser");
logcat-
org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2:8080 refused
PS-我尝试使用"ip address",127.0.0.1 AND localhost代替10.0.2.2的情况仍然相同.
PS - i've tried using "ip address" , 127.0.0.1 AND localhost instead of 10.0.2.2 still the same case.
清单文件中也有INTERNET和ACCESS_NETWORK_STATE的权限.
Also the permissions for INTERNET and ACCESS_NETWORK_STATE are also in the manifest file.
推荐答案
好的,问题已解决.
正如Codemon和Jayesh回答的那样,为了使用真实设备从Android Studio运行该应用程序,您必须使用服务器的IP地址代替10.0.2.2,并确保您的电话设备和服务器位于在同一网络中:-
As answered by both Codemon and Jayesh , in order to use real device to run the app from Android Studio , you have to use the ip address of the server in place of 10.0.2.2 and make sure your phone device and server are in the same network:-
HttpPost httpPost = new HttpPost("http://192.168.1.53:8080/webapp/CreateUser");
我想我的互联网连接不稳定,所以ip一直在变化,这就是为什么以前不起作用的原因.
I guess my internet connection was not stable , so ip was changing and thats why it didn't work before.
感谢您的帮助.
这篇关于HttpHostConnectException 10.0.2.2:8080被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!