首页 > Web开发 > 详细

Webclient "The operation has timed out" and override webclient with customized timeout

时间:2021-04-07 19:57:12      阅读:20      评论:0      收藏:0      [点我收藏+]
 1  public class WebDownload : WebClient
 2     {
 3         /// <summary>
 4         /// Time in milliseconds
 5         /// </summary>
 6         public int Timeout { get; set; }
 7 
 8         public WebDownload() : this(600000) { }
 9 
10         public WebDownload(int timeout)
11         {
12             this.Timeout = timeout;
13         }
14 
15         protected override WebRequest GetWebRequest(Uri address)
16         {
17             var request = base.GetWebRequest(address);
18             if (request != null)
19             {
20                 request.Timeout = this.Timeout;
21             }
22             return request;
23         }
24     }
25 
26 
27 
28 
29 static void WebDownloadDemo()
30         {
31             string url = "https://tfetimes.com/wp-content/uploads/2015/09/c-gui-programming-with-qt-4-2ndedition.pdf";
32             WebDownload wd = new WebDownload();
33             byte[] data = wd.DownloadData(url);
34             File.WriteAllBytes("aaaa.pdf", data);
35         }

 

Webclient "The operation has timed out" and override webclient with customized timeout

原文:https://www.cnblogs.com/Fred1987/p/14628123.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!