0

我的流浪机器上有 REST API 服务器。我在 c# (VS2015) 上为它编写客户端。

有相同的代码:

using (HttpClient client = new HttpClient())
{
    client.BaseAddress = new Uri(_server);
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

    HttpResponseMessage response = null;

    try
    {
         response = await client.GetAsync(_action);
    }
    catch (HttpRequestException e)
    {
        Debug.WriteLine(e.Message);
    }
}

麻烦:

抛出异常:mscorlib.ni.dll 中的“System.Net.Http.HttpRequestException”发送请求时出错。

如果我向另一个(非流浪)主机发送请求,一切都很好。

问题: 我该如何解决这个问题?

谢谢)

更新

堆栈跟踪

Exception thrown: 'System.Net.Http.HttpRequestException' in mscorlib.ni.dll
mess: An error occurred while sending the request.
   at System.Net.Http.HttpClientHandler.<SendAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Uborka.Models.ApiModel.<_Response>d__17.MoveNext()
4

0 回答 0