选择 ARM CPU 时 HttpClient GetAsync 失败

HttpClient GetAsync Failure when ARM CPU is Selected

在尝试调用 Rest 服务时,当 CPU 配置设置为 ARM

时,我不断收到以下错误

An error occurred while sending the request. The text associated with this error code could not be found.The server name or address could not be resolved

切换到任何CPUx86,调用成功。

代码示例:

System.Uri uri = new Uri("http://servername/__/__.svc/ID/123");

using (var client = new System.Net.Http.HttpClient())
       {
         try
            {
              var response = await client.GetAsync(uri);

              if (response.IsSuccessStatusCode)
                {
                    //handle success
                }
                else
                {
                    //handle failure   
                }
            }
            catch (HttpRequestException exc)
            {
                throw new HttpRequestException();
            }
        }

如何解释这个观察来解决问题?

注意:Package.appxmanifest 中功能下的应用专用网络(客户端和服务器)已启用。调用服务而不检查此功能曾经导致相同的错误。

使用 StackTrace 更新

at System.Net.Http.HttpClientHandler.d__86.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Net.Http.HttpClient.d__58.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at ProjectName.Views.MainPage.d__4.MoveNext()

简而言之,使用服务器 IP 地址而不是 host/server 名称,问题就解决了。否则,解析名称可能需要按照 here.

中所述编辑主机文件