2011-05-30 86 views
5

我试图连接到通过我的android应用程序通过导轨创建的restful web服务。连接到本地主机:3000在Android设备上拒绝

当我尝试连接到部署在http://localhost:3000我得到这个错误的REST API:

Connection to http://localhost:3000 refused.

我运行Ubuntu整洁的独角鲸。

通过浏览器打开此URL会正确地得到响应。

这怎么解决?

+0

通过设备上的浏览器访问该URL不会,因为服务器未在本地主机上运行,​​即设备本身,而是在远程计算机上运行。 – 2011-05-30 21:31:33

回答

7

如果您在您的设备上测试您的应用程序,那么localhost就是设备本身。如果你是在模拟器中进行测试,然后看看this文件

If you need to refer to your host computer's localhost, such as when you want the emulator client to contact a server running on the same host, use the alias 10.0.2.2 to refer to the host computer's loopback interface. From the emulator's perspective, localhost (127.0.0.1) refers to its own loopback interface.

在你的情况你的应用/活动,试图在3000端口不能连接到您的设备,您的主机。

+0

是的,localhost始终是设备或模拟器本身。仿真器具有开发机器的回送接口的别名,但USB连接的设备不具有。 – 2011-05-30 21:30:17

+0

啊,好的,谢谢克里斯(所以我也学到了......)。然后,天真的解决方法将连接到您的本地电脑与私人地址在您的无线局域网(如果你有) – thomas 2011-05-30 21:35:14

+0

是的。收集家伙。感谢很多。我已经从本地主机更改为10.0.2.2。 – rogerstone 2011-05-30 21:38:52

相关问题