zoukankan      html  css  js  c++  java
  • Make webclient support upload the large file which are larger than 1G

    step1: reconstruct the WebClient class

    public class MyWebClient : WebClient
        {
            
    protected override WebRequest GetWebRequest(Uri address)
            {
                HttpWebRequest request 
    = base.GetWebRequest(address) as HttpWebRequest;
                request.Timeout 
    = -1;
                request.CachePolicy 
    = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
                request.AllowWriteStreamBuffering 
    = false;
                
    return request;
            }
        }

    Step2: use new WebClient as the WebClient

                    WebClient web = new MyWebClient();
                    web.UploadFileCompleted 
    += new UploadFileCompletedEventHandler(web_UploadFileCompleted);
                    web.UploadProgressChanged 
    += new UploadProgressChangedEventHandler(web_UploadProgressChanged);
                    FileInfo fi 
    = new FileInfo(@"D:\VirtualBox VMs\VMxp\VMxp.vdi");
                    Uri uri 
    = new Uri("http://127.0.0.1:9090/upload");
                    web.UploadFileAsync(uri, fi.FullName);
  • 相关阅读:
    idea如何使用git关联远程仓库
    项目首次上传至git仓库步骤
    Eclipse 的 Java Web 项目环境搭建
    Postman
    Postman接口测试之POST、GET请求方法
    接口测试3A原则
    使用unittest和ddt进行数据驱动
    每天进步一点点006
    每天进步一点点005
    Selenium2+python自动化1-环境搭建(悠悠课程之路)
  • 原文地址:https://www.cnblogs.com/skyfei/p/2009122.html
Copyright © 2011-2022 走看看