by WebClient Way
WebClient client = new WebClient ();
String url= "Http://down6.3987.com:801/2010/office_3987.com.zip";
Stream STRM = client. OpenRead ("Http://down6.3987.com:801/2010/office_3987.com.zip");
String Filename=url. Substring (URL. LastIndexOf ('/') +1);
int count = 0;
byte[] buffer = new byte[4096];
FileStream fs = new FileStream (application.startuppath+ "//" +filename, FileMode.Create);
while ((count = Strm. Read (buffer, 0, buffer. Length)) > 0) {
Fs. Write (buffer, 0, count);
}
Fs. Close ();
Strm. Close ();
Strm. Dispose ();
Fs. Dispose ();
Through the original ecological HttpWebRequest Way
String url = "Http://down6.3987.com:801/2010/office_3987.com.zip";
string filename = URL. Substring (URL. LastIndexOf ('/') + 1);
Create an HTTP request in WebClient mode
HttpWebRequest req = (HttpWebRequest) httpwebrequest.create (URL); Create a link
Get Service its data
HttpWebResponse res = (HttpWebResponse) req. GetResponse ();
Stream MyStream = Res. GetResponseStream ();
Start file operation
FileStream fs = new FileStream (appdomain.currentdomain.basedirectory+ "//" +filename, FileMode.Create, FileAccess.Write, Fileshare.none);
Byte[] Buffer=new byte[1024];
int count=0;
while ((Count=mystream. Read (buffer,0,1024)) >0)
{
Fs. Write (buffer, 0, count);
}
Fs. Close ();
MyStream. Close ();
Fs. Dispose ();
Common ways to download HTTP requests in C # demo