How C # crawls Web content using HttpWebRequest, HttpWebResponse emulation browser

Source: Internet
Author: User

 Public stringGethtml (stringURL, Encoding ed) {            stringHtml =string. Empty;//Initializes a new WebrequstHttpWebRequest Request =(HttpWebRequest) webrequest.create (URL); Request.keepalive=true; Request.protocolversion=httpversion.version11; Request.method="GET"; Request.accept="*/* "; Request.useragent="mozilla/5.0 (Windows NT 6.1) applewebkit/536.5 (khtml, like Gecko) chrome/19.0.1084.56 safari/536.5"; Request.referer=URL; HttpWebResponse Htmlresponse=(HttpWebResponse) request.getresponse (); //returning data streams from Internet resourcesStream Htmlstream =Htmlresponse.getresponsestream (); //Read Data streamStreamReader Weatherstreamreader =NewStreamReader (Htmlstream, ed); //reading DataHtml =Weatherstreamreader.readtoend ();            Weatherstreamreader.close ();            Htmlstream.close ();            Htmlresponse.close (); //View HTML source files for different Web sites            returnHtml; }         Public stringGethtml (stringURL) {            returngethtml (URL, Encoding.UTF8); }

How C # crawls Web content using HttpWebRequest, HttpWebResponse emulation browser

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.