- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在等待 API 发布完成时抛出 AggregateException 我该如何解决这个问题?
我的API调用类似这样
using (var httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri(workflowUrl);
var task = httpClient.PostAsJsonAsync("api/apiname/execute/", executeModel)
.ContinueWith(x => x.Result.Content.ReadAsAsync<bool>().Result);
Task continuation = task.ContinueWith(x =>
{
bool response = x.Result;
});
continuation.Wait();
}
我在等待 POST 完成时收到下面给出的异常。
System.AggregateException was caught
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at
InnerException: System.AggregateException
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.get_Result()
at
at System.Threading.Tasks.Task`1.<>c__DisplayClass17.<ContinueWith>b__16(Object obj)
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
InnerException: System.AggregateException
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.get_Result()
at WebUI.ListController.<ListRepeater_ItemCommand>b__f(Task`1 x) in PostAsJsonAsync:line 741
at System.Threading.Tasks.Task`1.<>c__DisplayClass1a`1.<ContinueWith>b__19()
at System.Threading.Tasks.Task`1.InvokeFuture(Object futureAsObj)
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
InnerException: System.Threading.Tasks.TaskCanceledException
Message=A task was canceled.
InnerException:
最佳答案
您要发布大量数据吗?有一次我遇到了类似的问题。我相信潜在的问题是由于带宽问题偶尔超时。我尝试获取任务并手动等待它,然后检查 .IsFaulted
和 .IsCancelled
但 .Result
抛出 AggregateException
/任务取消异常
。
也许你应该尝试增加HttpClient.Timeout默认为 100 秒的属性?
关于c# - 等待 PostAsJsonAsync 时抛出 AggregateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20417383/
我的代码是 public class BaseDTO { public int Id { get; set; } public string Code { get; set; }
我创建了一个公开 REST 端点的 Azure 逻辑应用程序。 当我通过 postman 调用时,以下 JSON 主体工作正常。 { "to": "ggtest@yahoo.com", "
您好,我想捕获 PostAsJsonAsync 可能抛出的异常。我在微软网站上找不到任何关于此方法可能引发的异常的异常信息。我想处理任何可能的异常。 最佳答案 我相信因为它是 HttpClient 的
我正在尝试使用 HttpClient 和 C#。我正在尝试发布到 PHP REST 服务器并使用其返回的 JSON。当我发布到返回“Hello World!”的终点时一切安好。但是当它返回时{ "ke
我正在尝试使用 PostAsJsonAsync 调用 API,但它没有像我预期的那样工作。 repo : 创建一个 ASP.NET WebAPI 项目(.NET Framework 4.7.2) 将V
我在使用 PostAsJsonAsync(..) 时遇到了一个简单但烦人的问题扩展方法,我在任何地方都找不到有关解决以下问题的信息。 我的问题是生成的 Json 使用 PascaCasing我需要 c
这是我得到的错误: One or more errors occurred. at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean
我目前正在学习如何使用 OWIN 和 Katana 创建 C# 服务器。 我正在尝试回复 POST,但不幸的是它没有找到该功能。 这就是我所拥有的: 这是一个用户端类,它通过 POST 发送用户数据(
我正在尝试使用 SSIS 包中的一个 WEB API。我想在一个服务器文件夹中发布一个 pdf 文件。我为此创建了一个脚本任务。 但是当我执行那个包时,它给了我一些随机的运行时错误。 byte[] c
我目前正在向 API 发送一个 json 字符串以接收包含各种值的对象。 这是我发布的 json 字符串: {"SomeProperty":1,"DimensionOne":4,"DimensionT
我们正在使用 HttpClient 将 json 发布到 restful web 服务。在一个例子中,我们遇到了一些让我们感到困惑的事情。使用 postman、fiddler 等工具,我们可以发布到端
我有一个带有 WebAPI Controller 的 ASP.NET MVC 应用程序,以及一个使用这些 Controller 的控制台应用程序。控制台应用程序从计划任务运行并从远程源获取数据、解析数
我有这行代码 var response = new HttpClient().PostAsJsonAsync(posturi, model).Result; Called WebAPI Control
我将一个对象发布到 WebApi 方法。我正在使用 PostAsJsonAsync 来执行此操作。 public async Task PostAsync(string token, ServiceC
我有一个 Web api Controller ,我使用了 HttpClient PostAsJsonAsync() 方法;我的对象(Employee)是从基类(Person)继承的,但是在将对象发布
我在将 Web API 与 MVC 结合使用时遇到了一些问题,不确定是什么原因造成的,但它在 Debug模式下不会抛出任何异常或错误,请有人帮助解决这个问题。 代码如下: MVC Controller
我目前正在像这样发布到我的网络 api: client.PostAsJsonAsync("api/controller/methodincontroller", listOfProductObject
在等待 API 发布完成时抛出 AggregateException 我该如何解决这个问题? 我的API调用类似这样 using (var httpClient = new HttpClient())
我正在尝试使用 PostAsJsonAsync 以与更新前 PostJsonAsync 相同的方式使用,但我收到此错误: CS1503 参数 3:无法从 'ICCR.Shared.LoginModel
我在这里以及在the Elastic discussion forum上都发现了类似的问题,但不幸的是,所有答案都无济于事。 我目前正在使用ElasticSearch 7.0。 我想向我的Elasti
我是一名优秀的程序员,十分优秀!