方法一:

        string url_s = "http://www.baidu.com/ ";
        WebRequest request_o = WebRequest.Create(url_s);
        HttpWebResponse response_o = (HttpWebResponse)request_o.GetResponse();
        Stream html_o = response_o.GetResponseStream();
        StreamReader reader_o = new StreamReader(html_o, System.Text.Encoding.Default);
        string html_s = reader_o.ReadToEnd();
        reader_o.Close();
        html_o.Close();
        response_o.Close();
        Response.Write(Server.HtmlEncode( html_s));

    方法二:

              WebClient wc = new WebClient();
截取指定网站Html编码            wc.Credentials 
= CredentialCache.DefaultCredentials;
截取指定网站Html编码            Stream resStream 
= wc.OpenRead(web);
截取指定网站Html编码            StreamReader sr 
= new StreamReader(resStream, System.Text.Encoding.Default);
截取指定网站Html编码            code 
= sr.ReadToEnd();
截取指定网站Html编码            resStream.Close();

              ------------------------------

              WebClient wc = new WebClient();
截取指定网站Html编码            wc.Credentials 
= CredentialCache.DefaultCredentials;
截取指定网站Html编码            wc.Headers.Set(
"User-Agent""Microsoft Internet Explorer");//增加的代码伪装
截取指定网站Html编码
            Stream resStream = wc.OpenRead(web);
截取指定网站Html编码            StreamReader sr 
= new StreamReader(resStream, System.Text.Encoding.Default);
截取指定网站Html编码            code 
= sr.ReadToEnd();
截取指定网站Html编码            resStream.Close();

 

 

相关文章:

  • 2022-01-09
  • 2022-12-23
  • 2021-09-06
  • 2021-12-14
  • 2021-12-30
  • 2021-08-25
  • 2021-12-01
  • 2022-02-06
猜你喜欢
  • 2022-02-14
  • 2021-06-01
  • 2021-06-02
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
相关资源
相似解决方案