[C#] C#抓取网页内容的函数 →→→→→进入此内容的聊天室

来自 , 2019-06-04, 写在 C#, 查看 113 次.
URL http://www.code666.cn/view/003dd617
  1. private byte[] GetURLContents(string url)
  2. {
  3.     // The downloaded resource ends up in the variable named content.
  4.     var content = new MemoryStream();
  5.  
  6.     // Initialize an HttpWebRequest for the current URL.
  7.     var webReq = (HttpWebRequest)WebRequest.Create(url);
  8.  
  9.     // Send the request to the Internet resource and wait for
  10.     // the response.
  11.     using (WebResponse response = webReq.GetResponse())
  12.     {
  13.         // Get the data stream that is associated with the specified URL.
  14.         using (Stream responseStream = response.GetResponseStream())
  15.         {
  16.             // Read the bytes in responseStream and copy them to content.  
  17.             responseStream.CopyTo(content);
  18.         }
  19.     }
  20.  
  21.     // Return the result as a byte array.
  22.     return content.ToArray();
  23. }
  24. //csharp/6577

回复 "C#抓取网页内容的函数"

这儿你可以回复上面这条便签

captcha