C# Http地址下载文件到指定目录。
固定的地址列:"http://1.cn/2.rar"下载到指定目录:d:\文件夹\2.rar要完整代码button触发...
固定的地址 列:"http://1.cn/2.rar"
下载到指定目录: d:\文件夹\2.rar
要完整代码 button触发 展开
下载到指定目录: d:\文件夹\2.rar
要完整代码 button触发 展开
1个回答
展开全部
private void button_Click(object sender, EventArgs e)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://1.cn/2.rar");
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream responseStream = response.GetResponseStream();
Stream stream = new FileStream(@"d:\文件夹\2.rar", FileMode.Create);
byte[] bArr = new byte[1024];
int size = responseStream.Read(bArr, 0, bArr.Length);
while (size > 0)
{
stream.Write(bArr, 0, size);
size = responseStream.Read(bArr, 0, bArr.Length);
}
stream.Close();
responseStream.Close();
}
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://1.cn/2.rar");
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream responseStream = response.GetResponseStream();
Stream stream = new FileStream(@"d:\文件夹\2.rar", FileMode.Create);
byte[] bArr = new byte[1024];
int size = responseStream.Read(bArr, 0, bArr.Length);
while (size > 0)
{
stream.Write(bArr, 0, size);
size = responseStream.Read(bArr, 0, bArr.Length);
}
stream.Close();
responseStream.Close();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询