简体   繁体   English

在Android设备上拒绝Http连接

[英]Http Connection Refused on Android Device

I am having a problem to connect to the server via android application which is running on a device. 我在通过设备上运行的android应用程序连接服务器时遇到问题。 I could manage to connect the server on a emulator, but on the device it gives http connection refused error. 我可以设法在仿真器上连接服务器,但是在设备上却显示http连接被拒绝的错误。

07-08 09:53:27.125: W/System.err(8958): org.apache.http.conn.HttpHostConnectException: Connection to http://xx.xx.xx.xxx:8080 refused

I set up the server on a different laptop and the server is connected to university network wireless-ly and I am trying to connect to the server via the app on the device which is on the same network. 我将服务器设置在另一台笔记本电脑上,并且该服务器无线连接到大学网络,而我试图通过同一网络上设备上的应用程序连接到服务器。

What I don't understand is that there is no problem to connect the server on the emulator on a different computer, it gives connection failure when I test it on the actual device. 我不明白的是,在另一台计算机上的模拟器上连接服务器没有问题,当我在实际设备上对其进行测试时,它会导致连接失败。

I have googled for the matter, but they were usually related to ip address issues, such as localhost, 127.0.0.1 or 10.0.0.2. 我已经用谷歌搜索了此事,但​​它们通常与ip地址问题有关,例如localhost,127.0.0.1或10.0.0.2。 To me, it doesn't seem to be the same problem. 对我来说,这似乎不是一个相同的问题。

Please help me out! 请帮帮我!

Thanks in advance 提前致谢

Is that IP address accessible to outside world? 该IP地址是否可供外界访问?

Just a guess: I think the IP address, you were using might have been reserved. 只是一个猜测:我认为您使用的IP地址可能已被保留。 It worked in emulator cause you were still in the network (probably in your office). 它在模拟器中起作用,因为您仍在网络中(可能在您的办公室中)。 As you came outside the network with your real device it didn't work. 当您使用真实设备来到网络之外时,它就无法工作。

Since you are running the application in the emulator, which is a virtual machine, localhost and 127.0.0.1 points to the emulator itself. 由于您是在作为虚拟机的模拟器中运行应用程序,因此localhost127.0.0.1指向模拟器本身。

To access the network interface of your machine, you need to use the IP address 10.0.2.2 instead. 要访问计算机的网络接口,您需要使用IP地址10.0.2.2

I had the same problem and my answer was the firewall that blocked all the requests from outside, you can simply resolve this by temporary turn off your firewall. 我遇到了同样的问题,我的答案是防火墙阻止了来自外部的所有请求,您可以通过暂时关闭防火墙来解决此问题。 Other dummy possible causes in that the connection is refused: - your phone is connected to a different wifi (possible you forgot to change the networks) - clean/rebuild project (not in your case) - Internet permission from manifest (not in your case) - wrong url request (localhost or 127.0.0.1 instead the real machine ip eg: 192.168.0.101) 其他拒绝连接的可能原因:-您的手机已连接到其他wifi(可能您忘记了更改网络)-清理/重建项目(在您的情况下不是)-清单中的Internet许可(在您的情况下) )-错误的网址请求(localhost或127.0.0.1而不是真实机器的IP,例如:192.168.0.101)

if other people computer can open, your IP is banned from that page. 如果其他人的计算机可以打开,则该页面禁止了您的IP。 only your IP can't open, because that page block your IP 只有您的IP无法打开,因为该页面会阻止您的IP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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