1、WebClient:
System.Net.WebClient wc =newSystem.Net.WebClient();
Byte[] pageData= wc.DownloadData("网页地址");strings=System.Text.Encoding.Default.GetString(pageData);//s = System.Text.Encoding.UTF8.GetString(pageData);去除中文乱码
WebClient
2、HttPRequest:
1staticclassWebFunc2{3privatestaticCookieContainer cookie =newCookieContainer();4privatestaticstringcontentType ="application/x-www-form-urlencoded";5privatestaticstringaccept ="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, */*";6privatestaticstringuserAgent ="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)";78///<summary>9///10///</summary>11///<param name="url">网页地址</param>12///<param name="encoding">编码方式</param>13///<returns></returns>14publicstaticstringGetHtmlEx(stringurl, Encoding encoding)15{16HttpWebRequest request =(HttpWebRequest)WebRequest.Create(url);17request.UserAgent =userAgent;18request.ContentType =contentType;19request.CookieContainer =cookie;20request.Accept =accept;21request.Method ="get";2223WebResponse response =request.GetResponse();24Stream responseStream =response.GetResponseStream();25StreamReader reader =newStreamReader(responseStream, encoding);26String html =reader.ReadToEnd();27response.Close();2829returnhtml;30}31}
HttpRequest
转自http://blog.csdn.net/adsdassadfasdfasdf/article/details/5831347