[英]uwp, c# Dns.GetHostAddresses() not resolve hostname from hosts file
[英]UWP App cannot resolve local domain from hosts file
我有一个修改后的主机文件,如下所示:
192.168.10.10 library.test
我尝试像这样使用 HttpClient 从 UWP 应用程序连接到此域
var client = new HttpClient();
var result = await client.GetAsync("http://library.test");
Console.WriteLine(result.StatusCode);
但这失败了,但有以下例外
HResult=0x80072EFD
Message=An error occurred while sending the request.
Source=System.Net.Http
StackTrace:
at System.Net.Http.HttpClientHandler.<SendAsync>d__111.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__58.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at WordsmithsApp.ViewModels.LoginViewModel.<TryLogin>d__4.MoveNext() in C:\Users\dubif\mods-n-stuff\Coding\Projects\WordsmithsApp\WordsmithsApp\WordsmithsApp\ViewModels\LoginViewModel.cs:line 37
Inner Exception 1:
COMException: The text associated with this error code could not be found.
A connection with the server could not be established
当使用诸如https://google.com 之类的主机时,相同的代码可以正常工作
没有复现你的问题,当我尝试修改宿主机中的网站library.test
,指向本地网页时,可以正常访问。
请检查以下内容:
192.168.10.10
是可访问的 IP 地址吗? 如果只访问本地,可以改成127.0.0.1
。
如果不设置端口号,则默认访问80端口,请确保该端口下有可访问的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.