httpwebrequest
webclient
System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = System.Net.CredentialCache.DefaultCredentials;
Byte[] buffer= wc.DownloadData("");
string Content= System.Text.Encoding.Default.GetString(buffer);
webclient
System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = System.Net.CredentialCache.DefaultCredentials;
Byte[] buffer= wc.DownloadData("");
string Content= System.Text.Encoding.Default.GetString(buffer);
try
{
System.Net.WebRequest rqt = System.Net.WebRequest.Create(url); System.Net.WebResponse rsp = rqt.GetResponse(); System.IO.Stream respStream = rsp.GetResponseStream(); System.IO.StreamReader read = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("utf-8")); return read.ReadToEnd();
}
catch (Exception)
{
throw;
}
学人家的。
不行,这个只能到登陆界面的源码,如果有用户名,密码什么的,进不去我的IE已经打开在桌面,用户名密码登陆进去了,然后IE上有一些数据,这个时候点击IE的 查看--源码 , 是可以看到这些数据的,但是上面的代码不行
{
private static CookieContainer cookie = new CookieContainer();
private static string contentType = "application/x-www-form-urlencoded";
private static string accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";
private static string userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)"; public static string GetHtmlEx(string url, Encoding encoding)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.UserAgent = userAgent;
request.ContentType = contentType;
request.CookieContainer = cookie;
request.Accept = accept;
request.Method = "get"; WebResponse response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, encoding);
String html = reader.ReadToEnd();
response.Close(); return html;
}
}
//调用
WebFunc.GetHtmlEx("网址",Encoding....)