在C# Winform 应用程序中,获取某网页的源文件,可以用以下方法:
首先引入名称空间
using System.IO;
using System.Net;
WebClient MyWebClient = new WebClient();
MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据
Byte[] pageData = MyWebClient.DownloadData("http://www.baidu.com");
//string pageHtml = Encoding.Default.GetString(pageData);
FileStream file = new FileStream("C:\\test.html", FileMode.Create);
file.Write(pageData, 0, pageData.Length);