Httprequest:
Static class webfunc <br/>{< br/> Private Static cookiecontainer cookie = new cookiecontainer (); <br/> Private Static string contenttype = "application/X-WWW-form-urlencoded"; <br/> 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, */* "; <br/> 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) "; </P> <p> Public static string gethtmlex (string URL) <br/>{< br/> httpwebrequest request = (httpwe Brequest) webrequest. create (URL); <br/> request. useragent = useragent; <br/> request. contenttype = contenttype; <br/> request. cookiecontainer = cookie; <br/> request. accept = accept; <br/> request. method = "get"; </P> <p> webresponse response = request. getresponse (); <br/> stream responsestream = response. getresponsestream (); <br/> encoding = NULL; <br/> for (INT I = 0; I <response. headers. Count; I ++) <br/>{< br/> Match m = RegEx. Match (response. headers [I]. tostring (),"(? I )(? <= Charset =) [^] + "); <br/> If (! M. success) continue; <br/> encoding = encoding. getencoding (M. value); <br/> break; <br/>}< br/> streamreader reader = new streamreader (responsestream, encoding); <br/> string html = reader. readtoend (); <br/> response. close (); </P> <p> return HTML; <br/>}< br/>}
WebClient:
System. net. webClient WC = new system. net. webClient (); <br/> byte [] pagedata = WC. downloaddata ("webpage address"); <br/> string S = system. text. encoding. default. getstring (pagedata); <br/>