This article is a mirror article of machine translation, please click here to jump to the original article.

View: 18213|Reply: 0

[WinForm] C# gets the HTML source code returned by the URL

[Copy link]
Posted on 4/13/2015 11:16:00 PM | | |
  1. public string GetHttpWebRequest(string url)
  2.         {
  3.             Uri uri = new Uri(url);
  4.             HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(uri);
  5.             myReq.UserAgent = "User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705";
  6.             myReq.Accept = "*/*";
  7.             myReq.KeepAlive = true;
  8.             myReq.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.5");
  9.             HttpWebResponse result = (HttpWebResponse)myReq.GetResponse();
  10.             Stream receviceStream = result.GetResponseStream();
  11.             StreamReader readerOfStream = new StreamReader(receviceStream, System.Text.Encoding.GetEncoding("utf-8"));
  12.             string strHTML = readerOfStream.ReadToEnd();
  13.             readerOfStream.Close();
  14.             receviceStream.Close();
  15.             result.Close();
  16.             return strHTML;
  17.         }
Copy code






Previous:win32, win64 kill-free power lifting tool
Next:Listening to Xu Song's "Amazing Side".
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com