One or more errors occurred. (A task was canceled.)

c# 在使用HttpClient 请求api时,出现以下错误:

System.AggregateException: One or more errors occurred. (A task was canceled.)
 ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()

设置Timeout长一些就可以了

var client = new HttpClient ();
client.Timeout = TimeSpan.FromMinutes(3);
posted @ 2021-04-01 13:31  Cody&  阅读(7011)  评论(0)    收藏  举报