永远的SKYFEI
喜欢在阳光下,光着脊梁,挥汗如雨地工作,每次回头擦汗,看到的都是成就!

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);

 

 

posted on 2011-04-08 10:46  skyfei  阅读(452)  评论(0编辑  收藏  举报