//經過webClient方式web
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) {url
fs.Write(buffer, 0, count);ip
}
fs.Close();
strm.Close();
strm.Dispose();
fs.Dispose();string
//經過原生態HttpWebrequest方式it
string url = "http://down6.3987.com:801/2010/office_3987.com.zip";
string filename = url.Substring(url.LastIndexOf('/') + 1);
//用webClient方式建立http請求
HttpWebRequest req =(HttpWebRequest)HttpWebRequest.Create(url) ; //建立連接io
//獲取服務其數據
HttpWebResponse res = (HttpWebResponse)req.GetResponse();ast
Stream mystream = res.GetResponseStream();stream
//開始文件操做
FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory+"//"+filename, FileMode.Create, FileAccess.Write, FileShare.None);cli
byte[] buffer=new byte[1024];
int count=0;
while((count=mystream.Read(buffer,0,1024))>0)
{
fs.Write(buffer, 0, count);
}file
fs.Close(); mystream.Close(); fs.Dispose();