相思资源网 Design By www.200059.com

读取远程网页能做什么就不用多说了吧,做小偷程序或是采集,也就诸如此类了吧。

public string GetPage(string url)
{

  HttpWebRequest request = null;

  HttpWebResponse response = null;

  StreamReader reader = null;

  try
  {

    request = (HttpWebRequest)WebRequest.Create(url);

    request.Timeout = 20000;

    request.AllowAutoRedirect = false;

    response = (HttpWebResponse)request.GetResponse();

    if (response.StatusCode == HttpStatusCode.OK && response.ContentLength < 1024 * 1024)
    {

      reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);

      string html = reader.ReadToEnd();

      return html;

    }

  }

  catch
  {

  }

  finally
  {

    if (response != null)
    {

      response.Close();

      response = null;

    }

    if (reader != null)

      reader.Close();

    if (request != null)

      request = null;

  }

  return string.Empty;
}

标签:
HttpWebRequest,网页,源码

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“ASP.NET使用HttpWebRequest读取远程网页源代码”

暂无ASP.NET使用HttpWebRequest读取远程网页源代码的评论...