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