gpt4 book ai didi

asynchronous - HttpClient 任务被取消

转载 作者:行者123 更新时间:2023-12-03 07:46:22 24 4
gpt4 key购买 nike

我正在尝试使用 HttpClient 使用以下代码将消息异步记录到 REST 服务:

public void LogMessage(string operationURI, string message, EventLogEntryType logEntryType)
{
using (var client = new HttpClient())
{
var cancellationToken = new CancellationToken();
client.SendAsync(GetRequest(operationURI), cancellationToken).ContinueWith(
cw =>
{
var response = cw.Result; //(I get an error on this line)
if (!response.IsSuccessStatusCode)
{
LogMessageLocal(message, logEntryType);
}
});
}
}

注意:GetRequestMessage 返回一个 HttpRequestMessage。

但我收到一条错误消息,指出“任务已取消。”

有什么想法吗?

最佳答案

我相信当超过超时时就会发生这种情况。您可以检查您的timeout ,并记录异常发生之前未完成的时间,以查看是否超出了范围。

关于asynchronous - HttpClient 任务被取消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13017867/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com