C# winform 如何根据URL直接下载网页保存在本地?
2个回答
展开全部
用HttpWebRequest
和HttpWebResponse
然后再用文件流保存文件里
和HttpWebResponse
然后再用文件流保存文件里
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
像下面的这个样子
WebRequest webRequest = WebRequest.Create(url);
HttpWebRequest httpRequest = webRequest as HttpWebRequest;
Stream responseStream = httpRequest.GetResponse().GetResponseStream();
string stringResponse = string.Empty;
using(StreamReader responseReader =
new StreamReader(responseStream, Encoding.GetEncoding("gb2312")))
{
stringResponse = responseReader.ReadToEnd();
}
responseStream.Close();
WebRequest webRequest = WebRequest.Create(url);
HttpWebRequest httpRequest = webRequest as HttpWebRequest;
Stream responseStream = httpRequest.GetResponse().GetResponseStream();
string stringResponse = string.Empty;
using(StreamReader responseReader =
new StreamReader(responseStream, Encoding.GetEncoding("gb2312")))
{
stringResponse = responseReader.ReadToEnd();
}
responseStream.Close();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询