zoukankan      html  css  js  c++  java
  • Webclient "The operation has timed out" and override webclient with customized timeout

     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         }
  • 相关阅读:
    [ARC080D] Prime Flip
    硬币游戏
    点分治
    OneInDark对众数的爱
    [CF838D] Airplane Arrangements
    网络流总结(转载)
    二分图最大权完美匹配(KM)
    网络流
    FWT
    FFT & NTT
  • 原文地址:https://www.cnblogs.com/Fred1987/p/14628123.html
Copyright © 2011-2022 走看看