[英]Invalid HostName - Not able to connect IIS express from Android Emulator
我正在尝试从 Android 应用程序连接托管在本地 IIS express 上的 WCF 服务。 目前,我正在模拟器上对此进行测试。
服务的本地 URL 是
http:\/\/locahost:40000\/api\/Authenticate<\/code>
我知道 localhost 不起作用,我在代码中使用了 10.0.2.2
post = new HttpPost("http://10.0.2.2:40000/api/authenticate");
我尝试了其他有用的东西,我在IIS Express applicationhost.config文件绑定部分中添加了我的系统的IP地址。
<bindings>
<binding protocol="http" bindingInformation="*:40000:localhost" />
<binding protocol="http" bindingInformation="*:40000:192.168.5.118" />
</bindings>
我现在可以打电话给服务了
据我了解,10.0.2.2是127.0.0.1的别名,所以将它添加到您的站点的applicationhost.config
绑定,例如
<site name="MySite" id="1">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="{yourpath}" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:26013:localhost" />
<binding protocol="http" bindingInformation="*:26013:127.0.0.1" />
</bindings>
</site>
请记住,如果您使用Visual Studio,您的站点的相关applicationhost.config
可能不在c:\\users\\...
,而是在解决方案根目录下的.vs\\config
文件夹中。
在Visual Studio 2022<\/strong>上的.NetCore<\/strong>项目中,
我编辑了launchSettings.json<\/strong>文件,在 iisSettings > applicationUrl 下,我将 url 设置为
127.0.0.1<\/code>而不是
localhost<\/code> ,类似这样。
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://127.0.0.1:59109",
"sslPort": 0
}
}
在AndroidManifest.xml中添加Internet Permission
, Network State
和Wifi
权限
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.