C # Remote Access To webpage content

Source: Internet
Author: User
  1. Using system;
  2. Using system. Collections. Generic;
  3. Using system. text;
  4. Using system. net;
  5. Using system. IO;
  6. Namespace thief
  7. {
  8. Class Program
  9. {
  10. Static void main (string [] ARGs)
  11. {
  12. Try {
  13. WebClient mywebclient = new WebClient ();
  14. Mywebclient. Credentials = credentialcache. defaultcredentials; // gets or sets the network creden。 used to authenticate requests to Internet resources.
  15. Byte [] pagedata = mywebclient. downloaddata ("http://www.chinaaspx.com"); // download data from a specified website
  16. String pagehtml = encoding. Default. getstring (pagedata); // if you use gb2312 to retrieve the website page, use this sentence.
  17. // String pagehtml = encoding. utf8.getstring (pagedata); // if you get a website page using a UTF-8, use this sentence
  18. Console. writeline (pagehtml); // enter the obtained content on the console
  19. Using (streamwriter Sw = new streamwriter ("C: // test // ouput.html") // writes the obtained content to the text
  20. {
  21. Sw. Write (pagehtml );
  22. }
  23. Console. Readline (); // pause the console; otherwise, the console will be suspended.
  24. }
  25. Catch (webexception WebEx ){
  26. Console. writeline (WebEx. Message. tostring ());
  27. }
  28. }
  29. }
  30. }

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.