在Android模拟器上连接到localhost [英] Connection to localhost on the Android emulator

查看:96
本文介绍了在Android模拟器上连接到localhost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在android仿真器中连接到本地主机.

I can not connect to localhost in the android emulator.

我在Net Core 2中内置并在VS2017(Windows 10)中运行的API

The API I have built in Net Core 2 and running in VS2017 (Windows 10)

我检查的内容不起作用(不响应):

What I checked and does not work (does not react):

  • http://10.0.2.2:50069/api/values
  • http://ip:50069/api/values (ip -> ipv4 address from ipconfig)
  • http://127.0.0.1:50069/api/values
  • http://0.0.0.0:50069/api/values

我已经检查了所有关于网络上什么都没有的建议

I've already checked out all the advice on what was on the net and nothing

推荐答案

我在ASP.net中遇到了同样的问题.我通过更新IP绑定来解决此问题.

I had same problem with ASP.net. I fixed this problem by updating IP binding.

注意:在执行以下步骤之前,请确保保留项目的备份.

Note: Make sure to keep backup of your project before following steps.

为此,请执行以下步骤,

In order to do that follow the below steps,

  1. 转到您的项目文件夹.
  2. 找到并打开 .vs 文件夹(默认情况下它将被隐藏).
  3. 内部 .vs 文件夹中打开 config 文件夹.
  4. 您将获得 applicationhost.config ,其中包含与项目相关的设置.
  5. 在记事本,记事本++或任何其他喜欢的文本编辑器中打开它.
  6. 并找到以下代码.

  1. Go to your project folder.
  2. Find and open .vs folder (by default it'll be hidden).
  3. Inside .vs folder open config folder.
  4. There you get applicationhost.config which contains your project related settings.
  5. Open it in Notepad, Notepad++ or any other favorite text editor.
  6. And find the following piece of code.

<site name="YourAwesomeProject" id="2">
     <application path="/" applicationPool="Clr4IntegratedAppPool">
          <virtualDirectory path="/" physicalPath="/path/to/your/YourAwesomeProject" />
     </application>
     <bindings>
          <binding protocol="http" bindingInformation="*:50069:localhost" />
     </bindings>
</site>

  • 现在,您需要复制以下行并按照我的建议对其进行更新.这两行都是必需的,请勿删除第一行.

  • Now you need to duplicate the following line and update it as I suggest here. Both lines are required do not remove the first line.

    <binding protocol="http" bindingInformation="*:50069:localhost" />
    <binding protocol="http" bindingInformation="*:50069:*" />  <!-- add an asterisk in place of localhost -->
    

  • 然后重新启动服务器.

  • And restart the server.

    如果即使在更新文件后仍然无法使用,请关闭Windows防火墙或防病毒程序中的任何防火墙服务.

    If it doesn't work even after updating file, turn off Windows Firewall or any Firewall service from Antivirus programs.

    现在您可以使用IP地址访问API.

    Now you can access API with your IP address.

    http://<server_ip>:50069/api/values
    

    修改

    确保您正在以管理权限运行Visual Studio.

    Make sure that you're running Visual Studio with Administrative rights.

    这篇关于在Android模拟器上连接到localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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