14

我正在尝试将数据从在我的本地计算机上的 Android 模拟器中运行的 Android 应用程序发布到在 IIS Express 下运行的 Web 应用程序,该应用程序也在我的本地计算机上运行。不幸的是,当我从模拟器发布到 10.0.2.2 时,我收到一条Host Not Found错误消息。

如果我将 Web 应用程序配置为在 ASP.NET Dev Server (Cassini) 而不是 IIS Express 下运行,则 Android 应用程序可以毫无问题地发布。我为 IIS Express 缺少什么配置,阻止它使用来自 Android 模拟器的环回?

4

5 回答 5

19

授予自己绑定到 localhost 以外的网络适配器的权限,并将 IIS express 配置为绑定到所有适配器。

然后 IIS Express 将通过 10.0.2.2 接受来自 Android 模拟器的连接。如果您向防火墙添加规则,您还可以将 IIS Express 暴露给您的网络,这会降低安全性,但对于测试物理设备很有用。

步骤详细信息:(他们假设端口号为 5555 - 请改用您的实际端口)

  1. 以管理员身份从命令提示符运行:

    netsh http add urlacl url=http://*:5555/ user="NT AUTHORITY\INTERACTIVE"

  2. %USERPROFILE%\Documents\IISExpress\config\applicationhost.config中,将站点的 localhost 绑定替换为bindingInformation="*:5555:*". 结果应如下所示:

    <site name="..." id="...">
        <!-- application settings omitted for brevity -->
        <bindings>
            <binding protocol="http" bindingInformation="*:5555:*" />
        </bindings>
    </site>
于 2013-09-23T12:08:15.623 回答
12

将以下行添加到 IIs 配置文件(例如 c:\Users[YourName]\Documents\IISExpress\config\applicationhost.config )如果需要更改端口 8085..

<binding protocol="http" bindingInformation="*:8085:127.0.0.1" />

所以你的配置文件最终会是这样的

<bindings>
<binding protocol="http" bindingInformation="*:4396:localhost" />     // the existing one
<binding protocol="http" bindingInformation="*:8085:127.0.0.1" />     // new line
</bindings>

现在您可以通过调用端口 8085 从远程调用您的 Web 服务

ex from android emu.
new HttpPost("http://10.0.2.2:8085");
于 2014-10-18T06:57:35.163 回答
7

默认情况下,IIS Express 只接受来自 localhost 的连接。要启用来自远程设备的连接(并且模拟器也算在内),请使用此处的说明。

简而言之:

netsh http add urlacl url=http://[machinename]:[port]/ user=everyone
netsh http delete urlacl url=http://[machinename]:[port]/

[machinename]和替换[port]为您的计算机名称(或非本地 IP)和运行 IIS Express 的端口。

另外,请参阅这个问题和这个问题

于 2011-05-31T20:37:55.233 回答
0

这是我的解决方案:我正在使用 Visual Studio Express 2013 for Web,并且我的 RESTful Web 服务在 IIS express 上运行。当我尝试在同一台机器上使用 Android 模拟器访问我的 Web 服务时,它给了我这个无效的主机名错误。正如上面的答案所建议的,我确实向我的 applicationhost.config 文件添加了新的绑定,但它仍然没有工作。最后,我能够通过“以管理员身份”运行 Visual Studio 来解决这个问题。

于 2014-12-10T01:06:02.650 回答
0

您需要为您的 PC 名称添加一个新绑定,或者将绑定更改为*:<port>:*or:<port>:然后允许该端口使用具有高级安全性的 Windows 防火墙

要查看的文件<solution folder>\.vs\<project name>\config\applicationhost.config在第 167 行附近

于 2021-12-05T12:42:33.007 回答