首页 > 解决方案 > HttpClient 超时和 CancelationToken 不起作用

问题描述

我最近从 2017 年到 2019 年更新了我的 Visual Studio。我使用 HttpClient 实现作为默认值。在 vs2017 中一切都运行良好。在我将我的 vs 更新到 2019 之后。然后当我使用 httpClient 时,超时和取消令牌不起作用。

这是我的代码:

var token = cts.Token;
using (var client = new HttpClient())
{
    client.Timeout = TimeSpan.FromSeconds(20);
    var response = await client.PostAsync("http://" + MyIp + ":9090/api/SqlAction/", new StringContent("my data", Encoding.UTF8, "application/json"), token);
    if (response.IsSuccessStatusCode)
    {
    }
}

标签: androidxamarinhttpclient

解决方案


推荐阅读