2017-04-25 107 views
3

我知道类似的问题已被问了很多次,但我仍然无法正常工作。我希望能够从我的Visual Studio Android模拟器访问我的主机上的IIS Express。我在我的.VS以下绑定\设置\ applicationHost.config文件为我的网站:从Android模拟器IIS快速访问

<binding protocol="http" bindingInformation="*:7265:MyComp" /> 
<binding protocol="https" bindingInformation="*:44300:MyComp" /> 
<binding protocol="http" bindingInformation="*:7265:10.0.2.2" /> 
<binding protocol="https" bindingInformation="*:44300:10.0.2.2" /> 
<binding protocol="http" bindingInformation="*:7265:localhost" /> 
<binding protocol="https" bindingInformation="*:44300:localhost" /> 

当我运行我的主机上的网站,在运行的应用程序列表中,我看到MyComp的绑定和localhost列出,但不是10.0.2.2的。在我的主机上,我可以使用MyComp或localhost进行连接而没有问题。

在模拟器中,我可以使用http://10.0.2.2连接到我的主机上的IIS 7.5(不是快速),没有问题。在我的模拟器中,我不能做的是连接到http://10.0.2.2:7265https://10.0.2.2:44300这是IIS Express中运行的站点。我收到HTTP 400错误“请求主机名无效。”。我确定这是因为我没有正确设置IIS绑定,但没有任何我尝试工作。有任何想法吗?

谢谢!

+0

你尝试您的计算机名称,而不是IP的。 –

+0

我确实尝试过,但是我得到的主机名未找到DNS错误。我是Android开发新手,但在印象中,您必须使用几个特定的​​IP中的一个来连接主机.... – NorthFork

回答

1

您错过了一些基本事实。 Android模拟器上的10.0.2.2在主机上转换为127.0.0.1。因此,改变你的绑定

<binding protocol="http" bindingInformation="*:7265:127.0.0.1" /> 
<binding protocol="https" bindingInformation="*:44300:127.0.0.1" /> 

您还可以从绑定通过下面的这篇博客文章删除主机头,

https://blog.lextudio.com/how-to-let-android-emulator-access-iis-express-f6530a02b1d3

+0

感谢您的澄清。我结束了切换到项目上的常规IIS而不是IIS Express,所以我无法测试您的答案,但这是有道理的... – NorthFork