usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Net;usingSystem.Text;namespacehttpdemo{classprogram{//the path to downloadStatic stringURL ="Http://www.aseoe.com/demo/api/jquery_aseoe_001.zip";//get full file nameStatic stringFileName =path.getfilename (URL);//Save PathStatic stringLocalPath ="d:\\httpceshi\\"+FileName;//The appended. temp suffix name is not finished downloadingStatic stringTempPath = LocalPath +". Temp";//offset (breakpoint)Static intPos;Static voidMain (string[] args) {DownLoad (); Console.ReadLine ();} Public Static voidDownLoad () {//End If there is a file to updateif(File.exists (localPath))return; Stream Localfs=NULL;//If no files have been uploaded (requires a breakpoint to continue file)if(File.exists (TempPath)) {Localfs=NewFileStream (TempPath, FileMode.Open);}Else{Localfs=NewFileStream (TempPath, FileMode.Create);}//Get Breakpointpos = (int) Localfs. Length; HttpWebRequest Request=(HttpWebRequest) webrequest.create (URL); request. Headers.add ("Accept-charset","Gbk,utf-8"); request. UserAgent="mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2;. NET CLR 1.0.3705;)"; request. Method="GET"; request. Timeout=30000;//Total file length unit (B)LongTotal =request. GetResponse (). ContentLength; Console.WriteLine ("The total length is:"+Total );if(Pos >0) Request. AddRange (POS);//Offset to breakpointHttpWebResponse Responseresult=(HttpWebResponse) request. GetResponse ();using(Stream stream =Responseresult.getresponsestream ()) {byte[] buffer =New byte[Total-POS];intReadSize = stream. Read (Buffer,0, buffer. Length); while(ReadSize >0) {Localfs. Write (Buffer,0, readsize); ReadSize= Stream. Read (Buffer,0, buffer. Length); Console.WriteLine ("have downloaded:"+Localfs. Length);} Localfs. Close (); File.move (TempPath, localPath);//change temporary file to normal file suffixConsole.WriteLine ("Download Complete!!!");}}}}
C # HTTP protocol breakpoint continuation