使用C# Winform应用程序获取网页源文件的解决方法
摘要:在C#Winform应用程序中,获取某网页的源文件,可以用以下方法:首先引入名称空间usingSystem.IO;usingSystem.N...
在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);
【使用C# Winform应用程序获取网页源文件的解决方法】相关文章:
★ C# WinForm捕获全局变量异常 SamWang解决方法
上一篇:
使用C#获取系统特殊文件夹路径的解决方法
下一篇:
解决C#全屏幕截图的实现方法