您的位置:首页 > 编程语言 > C#

c# 用System.Net 读取网页源代码(2)

2007-02-07 11:30 232 查看
接上一篇,这是普遍采用的 c# 用System.Net 读取网页源代码 的书写方式。

System.Net.HttpWebRequest req;
System.Net.HttpWebResponse res;
string url="http://www.92liao.cn";
req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
res = (System.Net.HttpWebResponse)req.GetResponse();
System.IO.StreamReader strm = new System.IO.StreamReader(res.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));
string aa=strm.ReadToEnd();
Response.Write(aa);

方法2

在WindowsApplication 用WebBrowser控件实现 读取网页。
在工具箱里右击,选添加/删除选项,在弹出的对话框里选Com组件选项卡,找到
Microsoft Web 浏览器 选定 后确定, 在工具箱里选择WebBrowser控件,拖放到窗体上,然后写代码:

private void Form1_Load(object sender, System.EventArgs e)
{
string str="";
System.Object nullObject=0;
System.Object nullObjStr=str;
this.axWebBrowser1.Navigate("www.88te.net",ref nullObject,ref

nullObjStr,ref nullObjStr,ref nullObjStr);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: