【发布时间】:2020-02-08 14:50:59
【问题描述】:
我有一个修改过的hosts文件如下:
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这样的主机时也能正常工作
【问题讨论】:
-
192.168.10.10 是一台不同的机器,还是您正在运行应用程序的同一台机器?如果是同一台机器,不妨看看这篇文章:stackoverflow.com/questions/34589522/…