简体   繁体   English

在 Android 设备上连接到 localhost:3000 被拒绝

[英]Connection to localhost:3000 refused on Android device

I am trying to connect to the restful web service i created through rails from my android app.我正在尝试连接到我通过我的 android 应用程序的轨道创建的宁静的 web 服务。

When I try to connect to the REST API deployed on http://localhost:3000 I get this error:当我尝试连接到部署在http://localhost:3000上的 REST API 时,我收到此错误:

Connection to http://localhost:3000 refused.http://localhost:3000的连接被拒绝。

I am running ubuntu natty narwhal.我正在运行 ubuntu natty narwhal。

Hitting this URL via a browser gets the response properly.通过浏览器点击这个 URL 可以获得正确的响应。

How can this be solved?如何解决?

If you are testing your app on your device then localhost is the device itself.如果您在设备上测试您的应用程序,那么 localhost 就是设备本身。 If you are testing in the emulator then take a look atthis document如果您在模拟器中进行测试,请查看文档

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.如果您需要引用主机的 localhost,例如当您希望模拟器客户端联系运行在同一主机上的服务器时,请使用别名 10.0.2.2 来引用主机的环回接口。 From the emulator's perspective, localhost (127.0.0.1) refers to its own loopback interface.从模拟器的角度来看,localhost (127.0.0.1) 指的是它自己的环回接口。

In your case your app/activity is trying to connect on port 3000 to your device not to your host computer.在您的情况下,您的应用程序/活动正在尝试将端口 3000 连接到您的设备而不是您的主机。

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

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