首页 > 开发 > 综合 > 正文

读取网页数据

2024-07-21 02:26:16
字体:
来源:转载
供稿:网友
  public string getweb(string website)
  {
   try
   {
    string strhtmlcontent="";
    string sourceurl=website;
    system.net.httpwebrequest myrequest=(system.net.httpwebrequest)system.net.webrequest.create(sourceurl);
    myrequest.timeout=5000;
    myrequest.headers.set("pragma", "no-cache");
    system.net.httpwebresponse myresponse=(system.net.httpwebresponse)myrequest.getresponse();
    system.io.stream mystream=myresponse.getresponsestream();
    system.text.encoding myencoding=system.text.encoding.getencoding("gb2312");
    system.io.streamreader mystreamreader=new system.io.streamreader(mystream,myencoding);
    strhtmlcontent=mystreamreader.readtoend();
    return strhtmlcontent;   
   }
   catch
   {
    return "读取错误";
   }
  } 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表