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

    技术2022-05-11  72

    接上一篇,这是普遍采用的 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);     }


    最新回复(0)