暴露在本地主机上运行的Andr​​oid模拟器服务? [英] Exposing a service running on localhost to an Android emulator?

查看:120
本文介绍了暴露在本地主机上运行的Andr​​oid模拟器服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过ASP.net/Visual Studio中的结合正在开发Android应用程序的服务。当我运行通过VS的服务,这是在访问的http://本地主机:13980 / 而不是 http://127.0.0.1:13980/ (其中给出了一个错误的请求 - 无效的主机名400错误)。很显然,我不能告诉Android应用程序寻找一个服务于本地主机,因为这会在自己被人指指点点。

I'm running a service through ASP.net/Visual Studio that's being developed in conjunction with an Android app. When I run the service through VS, it's accessible at http://localhost:13980/ but not http://127.0.0.1:13980/ (which gives a "bad request - invalid hostname" 400 error). Obviously, I can't tell the Android app to look for a service at "localhost" since that'll be pointing at itself.

我的理解(<一个href=\"http://stackoverflow.com/questions/5806220/how-to-connect-to-my-http-localhost-web-server-from-android-emulator-in-eclips\">according这个页面)的Andr​​oid模拟器对待10.0.2.2作为一个传递IP地址的主机的127.0.0.1,所以它会站在我要是一)得到本地主机是有理由相信,一切都会走到一起通过127.0.0.1正确曝光,和b)中的应用改变了目标地址从本地主机:端口10.0.2.2:port~~V

I understand (according to this page) that the Android emulator treats 10.0.2.2 as a pass-through IP address to the host machine's 127.0.0.1, so it would stand to reason that everything would come together if I a) got localhost to be properly exposed through 127.0.0.1, and b) changed the target address in the app from localhost:port to 10.0.2.2:port.

我怎么会去这样做A部分?我运行Windows 8.1专业版时,Visual Studio 2012,并在有关项目的目标是.NET 4.5。

How would I go about doing part A? I'm running Windows 8.1 Pro, Visual Studio 2012, and the project in question is targeting .NET 4.5.

谢谢!

推荐答案

您有两种选择:


  1. 运行IIS,而不是卡西尼VS下的Web服务。这样,您就可以将Web服务绑定到你的本地网络的IP地址,例如 http://10.0.2.2:8081

  2. 修改主机上的Andr​​oid模拟器文件重定向本地主机到您的计算机的IP地址

第二个是不是一个很好的解决方案。这可能会导致与OS一些冲突,我甚至不能确定卡西尼号仍将甚至服务请求。 Visual Studio的内置Web服务器(卡西尼)只听本地请求,所以选项(1)真的是最灵活的。另外,既然你有W8临 IIS已经内置

The second one isn't a great solution. It may cause some conflicts with the OS and I'm not even sure Cassini would still even serve the request. Visual Studio's in-built web server (Cassini) only listens to local requests, so option (1) really is the most flexible. Plus, since you have W8 Pro IIS is already built-in.

这篇关于暴露在本地主机上运行的Andr​​oid模拟器服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆