Android: "Bad Request-Invalid Hostname"从模拟器访问本地主机时

标签 android android-emulator localhost

我无法将 localhost 与 xamarin.android 应用程序一起使用。 我在 Chrome 浏览器上执行了 Web 项目和服务项目(不是移动应用程序)。

This is emulators executed project

显示的端口号我尝试通过分别附加 10.0.2.2: 和 10.0.3.2: 在 Android Studio 模拟器和 Genymotion 模拟器中浏览,我得到了结果 Bad Request-Invalid Hostname。即使我已经尝试过 Service project port number,但都无法正常工作。

Web 项目:使用 Visual Studio 2017 的 ASP.NET 项目和在同一解决方案中拥有服务项目。

最佳答案

打开您的解决方案文件夹。您可能在 1 个文件夹中有多个项目,您不需要项目的文件夹,而是根文件夹。在里面你会有.vs/config/applicationhost.config文件,打开它。

查找<sites>如果您在一个解决方案中切换启动项目,您将在其中拥有正在运行的站点,可能有多个站点。当您右键单击它的图标时,该名称将与 IIS 在任务栏中显示的名称相对应。例如,标签可以是 <site name="ServerApp" id="2"> . 现在你需要添加一行来绑定(bind)外部连接到你的机器ip,例如

      <site name="ServerApp" id="2">
...
        <bindings>
...
          <binding protocol="http" bindingInformation="*:60424:127.0.0.1" />
        </bindings>
      </site>

设置适当的端口号和协议(protocol),这里重要的是将它们映射到127.0.0.1 ,而不是“本地主机”,那么它们将可通过10.0.2.2:60424用于安卓模拟器。 (端口号 60424 只是来自上面的例子,使用你的)

关于Android: "Bad Request-Invalid Hostname"从模拟器访问本地主机时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49270453/

相关文章:

android - 如何在工具栏中的菜单旁边添加微调器

Android 模拟器卡在 "Google Play Services are Updating"

jakarta-ee - 如何将用户从/页面重定向到 html 页面?

github - Jenkins 和 Github 自动触发

android - 为什么 GPS 数据在市区不准确?

android - 将 ListView 行最小化为一行

android - 为什么是android :transcriptMode ="normal" not working properly?

android - 运行 Google map Activity 时出现空白网格 + 没有可用于测试 Google map 的模拟器

android-emulator - 如何在 Android Studio 中修复 "Could not initialize DirectSoundCapture"

apache - 通过 LAN 网络从另一台计算机访问 localhost (xampp) - 如何?