WebClient:如何取消长时间运行的 HTTP 请求? [英] WebClient: how to cancel a long running HTTP request?

查看:61
本文介绍了WebClient:如何取消长时间运行的 HTTP 请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WebClient 向运行时间很长的 API 发出请求.但我实际上并不需要知道结果,我只需要开始这个过程.

I'm using WebClient to make a request to an API that has a very long running process. But I don't actually need to know the result, I only need the process to be started.

这个过程是成功还是失败对我来说并不重要.所以我想在提出请求后立即断开连接.

It doesn't matter to me if the process succeeds or fails. So I want to drop the connection as soon as I have made the request.

如何断开网络客户端的连接?我不想等待 30 - 60 秒的响应:

How can I drop the webclient's connection? I don't want to wait 30 - 60 seconds for the response:

var client = new WebClient();
string url = "http://example.com/SomeVeryLongRunningProcess/parameter";
client.BeginDownloadString(uri);
client.DropConnection; // how do I drop the connection before the response is received?

推荐答案

您可以使用:client.CancelAsync()

这篇关于WebClient:如何取消长时间运行的 HTTP 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆