使用C# Winform应用程序获取网页源文件的解决方法
使用C# Winform应用程序获取网页源文件的解决方法
发布时间:2016-12-28 来源:查字典编辑
摘要:在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#教程学习
热门C#教程学习
编程开发子分类