在 Android 模拟器上连接到本地主机
Connection to localhost on the Android emulator
我无法在 android 模拟器中连接到本地主机。
我在 Net Core 2 中构建的 API 和在 VS2017 中构建的 运行 (Windows 10)
我检查过但不起作用(没有反应)的内容:
- http://10.0.2.2:50069/api/values
- http://ip:50069/api/values(ip -> 来自 ipconfig 的 ipv4 地址)
- http://127.0.0.1:50069/api/values
- http://0.0.0.0:50069/api/values
我已经检查过所有关于网上内容的建议
我和 ASP.net 有同样的问题。我通过更新 IP 绑定解决了这个问题。
注意:确保在执行以下步骤之前备份您的项目。
为了做到这一点,请按照以下步骤操作,
- 转到您的项目文件夹。
- 找到并打开
.vs
文件夹(默认隐藏)。
- 在
.vs
文件夹中打开 config
文件夹。
- 您会得到
applicationhost.config
,其中包含您的项目相关设置。
- 在记事本、Notepad++ 或任何其他喜欢的文本编辑器中打开它。
并找到下面这段代码。
<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>
现在您需要复制以下行并按照我在此处的建议进行更新。两行都需要不要去掉第一行。
<binding protocol="http" bindingInformation="*:50069:localhost" />
<binding protocol="http" bindingInformation="*:50069:*" /> <!-- add an asterisk in place of localhost -->
并重启服务器。
如果即使在更新文件后仍无法正常工作,请关闭 Windows 防火墙或防病毒程序中的任何防火墙服务。
现在您可以使用您的 IP 地址访问 API。
http://<server_ip>:50069/api/values
编辑
确保您 运行 Visual Studio 具有管理权限。
我无法在 android 模拟器中连接到本地主机。
我在 Net Core 2 中构建的 API 和在 VS2017 中构建的 运行 (Windows 10)
我检查过但不起作用(没有反应)的内容:
- http://10.0.2.2:50069/api/values
- http://ip:50069/api/values(ip -> 来自 ipconfig 的 ipv4 地址)
- http://127.0.0.1:50069/api/values
- http://0.0.0.0:50069/api/values
我已经检查过所有关于网上内容的建议
我和 ASP.net 有同样的问题。我通过更新 IP 绑定解决了这个问题。
注意:确保在执行以下步骤之前备份您的项目。
为了做到这一点,请按照以下步骤操作,
- 转到您的项目文件夹。
- 找到并打开
.vs
文件夹(默认隐藏)。 - 在
.vs
文件夹中打开config
文件夹。 - 您会得到
applicationhost.config
,其中包含您的项目相关设置。 - 在记事本、Notepad++ 或任何其他喜欢的文本编辑器中打开它。
并找到下面这段代码。
<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>
现在您需要复制以下行并按照我在此处的建议进行更新。两行都需要不要去掉第一行。
<binding protocol="http" bindingInformation="*:50069:localhost" /> <binding protocol="http" bindingInformation="*:50069:*" /> <!-- add an asterisk in place of localhost -->
并重启服务器。
如果即使在更新文件后仍无法正常工作,请关闭 Windows 防火墙或防病毒程序中的任何防火墙服务。
现在您可以使用您的 IP 地址访问 API。
http://<server_ip>:50069/api/values
编辑
确保您 运行 Visual Studio 具有管理权限。