访问本地主机:端口从Android模拟器 [英] Accessing localhost:port from Android emulator
问题描述
我跑,在运行在我的本地机器的Web服务本地主机:54722
我想从在Android模拟器中运行的应用程序调用该服务。
I want to call the service from an app running in the Android emulator.
我看了,在应用程序中使用 10.0.2.2
将访问本地主机,但它似乎不使用的端口号以及工作。它说的Htt presponseException:错误的请求
I read that using 10.0.2.2
in the app would access localhost, but it doesn't seem to work with the port number as well. It says HttpResponseException: Bad Request
.
推荐答案
然而,有一个更好的解决方案。您可以使用IP地址 10.0.2.2
访问你的主机。
There is however a far better solution. You can access your host machine with the IP address "10.0.2.2
".
本已经以这种方式设计的Android团队。所以,你的Web服务器可以完美运行在本地主机和从你的Android应用程序,你可以通过访问 http://10.0.2.2:<hostport>
This has been designed in this way by the Android team. So your webserver can perfectly run at localhost and from your Android app you can access it via "http://10.0.2.2:<hostport>
".
这篇关于访问本地主机:端口从Android模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!