Android 模拟器环回 IIS Express 不起作用,但可以与 Cassini 一起使用
我正在尝试将本地计算机上 Android 模拟器中运行的 Android 应用程序中的数据发布到也在本地计算机上运行的 IIS Express 下运行的 Web 应用程序。不幸的是,当我从模拟器发布到 10.0.2.2 时,我收到一条 Host Not Found
错误消息。
如果我将 Web 应用程序配置为在 ASP.NET Dev Server (Cassini) 而不是 IIS Express 下运行,则 Android 应用程序能够正常发布。我缺少 IIS Express 的哪些配置,导致它无法使用 Android 模拟器的环回?
I am attempting to post data from an Android application running in the Android Emulator on my local machine to a web application running under IIS Express also running on my local machine. Unfortunately, when I post to 10.0.2.2 from the emulator I receive a Host Not Found
error message.
If I configure the web application to run under ASP.NET Dev Server (Cassini) instead of IIS Express the Android application is able to post with no problems. What configuration am I missing for IIS Express that is preventing it from working with a loopback from the Android emulator?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
授予您自己绑定到 localhost 以外的网络适配器的权限,并将 IIS Express 配置为绑定到所有适配器。
然后,IIS Express 将通过 10.0.2.2 接受来自 Android 模拟器的连接。如果向防火墙添加规则,还可以将 IIS Express 暴露到网络,这会降低安全性,但对于测试物理设备很有用。
步骤详细信息:(假设端口号为 5555 - 请使用您的实际端口)
以管理员身份从命令提示符运行此命令:
netsh http add urlacl url=http://*:5555/ user="NT AUTHORITY\INTERACTIVE"
In %USERPROFILE%\Documents\IISExpress\config\applicationhost.config,将站点的本地主机绑定替换为
bindingInformation="*:5555:*"
。结果应如下所示:Grant yourself permission to bind to network adapters other than localhost, and configure IIS express to bind to all adapters.
IIS Express will then accept connections from the Android emulator via 10.0.2.2. If you add a rule to the firewall, you can also expose IIS Express to your network, which decreases security but is useful for testing physical devices.
Step details: (they assume a port number of 5555 - use your actual port instead)
Run this from a command prompt as Administrator:
netsh http add urlacl url=http://*:5555/ user="NT AUTHORITY\INTERACTIVE"
In %USERPROFILE%\Documents\IISExpress\config\applicationhost.config, replace your site's localhost binding with
bindingInformation="*:5555:*"
. The result should look like this:将以下行添加到 II 配置文件中(例如 c:\Users[YourName]\Documents\IISExpress\config\applicationhost.config )如果需要,请更改端口 8085..
这样您的配置文件最终会出现类似这样的内容,
现在您可以通过调用端口 8085 从远程调用您的 Web 服务
Add following line to IIs config file (ex c:\Users[YourName]\Documents\IISExpress\config\applicationhost.config ) Change the port 8085 if required..
so your config file will end-up with something like this
now you can call your web service from remote by calling to port 8085
默认情况下,IIS Express 仅接受来自本地主机的连接。要启用来自远程设备的连接(模拟器也算在内),请使用 此处。
简而言之:
将
[machinename]
和[port]
替换为您的计算机名称(或非本地 IP)和 IIS Express 运行的端口。另请参阅此问题和此一个。
By default, IIS Express only accepts connections from localhost. To enable connections from remote devices (and the emulator counts as such), use the instructions from here.
In short:
Replace
[machinename]
and[port]
with your computer name (or non-local IP) and port IIS Express runs on.Also, see this question and this one.
这是我的解决方案:
我正在使用 Visual Studio Express 2013 for Web,并且我的 RESTful Web 服务在 IIS Express 上运行。
当我尝试在同一台计算机中使用 Android 模拟器访问我的 Web 服务时,它给了我这个无效主机名错误。正如上面的答案所建议的,我确实向我的 applicationhost.config 文件添加了新的绑定,但它仍然不起作用。最后,我通过“以管理员身份”运行 Visual Studio 解决了这个问题。
Here is my solution:
I am using Visual Studio Express 2013 for Web and my RESTful web service is running on IIS express.
When I tried to access my web service using an Android emulator in the same machine it gave me this invalid hostname error. As suggested by above answers I did add new bindings to my applicationhost.config file but still it didn't work. At last, I was able to fix this issue by running Visual Studio "as administrator".
您需要为您的电脑名称添加新的绑定,或将绑定更改为
*::*
或::
,然后允许该端口使用具有高级安全性的 Windows 防火墙。要查看的文件是第 167 行左右的
<解决方案文件夹>\.vs\<项目名称>\config\applicationhost.config
You need to add a new binding for your PC name or change a binding to
*:<port>:*
or:<port>:
and then allow that port using Windows Firewall with Advanced Security.File to look into is
<solution folder>\.vs\<project name>\config\applicationhost.config
around line 167