android - 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)
{
}
}
解决方案
推荐阅读
- python - Telegram Bot 获取用户电话号码
- javascript - How can Babel be used without bundler, but with a dev-experience similar to webpack?
- powershell - For PowerShell cmdlets, can I always pass a script block to a string parameter?
- python-3.x - 如何从 youtube 频道获取所有视频
- android - Unit testing Retrofit calls when service is injected with Dagger 2
- sql - 来自 Hive 格式的表的艰巨选择语句
- unity3d - 过滤器下已经存在sqlite3.dll
- javascript - 为什么分配给“window”的函数和类在 GreaseMonkey 脚本中不相等?
- javascript - 拒绝执行内联脚本 Javascript Chrome 扩展
- java - 不知道如何操作字符串