.NET HTTP异步请求(适用于并发请求同时大于上千上万个)
2021-02-10 20:19
标签:private The cte 异步请求 begin public string str console 方法 一: WebRequest Request= WebRequest.Create(strURL); protected void OnResponse(IAsyncResult ar) 方法二: .NET HTTP异步请求(适用于并发请求同时大于上千上万个) 标签:private The cte 异步请求 begin public string str console 原文地址:https://www.cnblogs.com/CHPowerljp-IT/p/13046719.html
Request.BeginGetResponse(new AsyncCallback(OnResponse), Request);
{
WebRequest wrq = (WebRequest)ar.AsyncState;
WebResponse wrs = wrq.EndGetResponse(ar);
// read the response ...
}class Program
{
private const string url = "http://";
static async Task Main(string[] args)
{
await AsyncTestTask();
}
public static async Task AsyncTestTask()
{
Console.WriteLine("当前任务Id是:"+Thread.CurrentThread.ManagedThreadId);
Console.WriteLine(nameof(AsyncTestTask));
using (var client = new WebClient())
{
string content = await client.DownloadStringTaskAsync(url);
Console.WriteLine("当前任务Id是:"+Thread.CurrentThread.ManagedThreadId);
Console.WriteLine(content.Substring(0,100));
Console.ReadLine();
}
}
}
上一篇:【CSS基础】CSS常见问题
下一篇:Css Secret 案例全套
文章标题:.NET HTTP异步请求(适用于并发请求同时大于上千上万个)
文章链接:http://soscw.com/index.php/essay/53729.html