[C#] C#抓取网页代码存在字符串里 →→→→→进入此内容的聊天室

来自 , 2021-02-21, 写在 C#, 查看 112 次.
URL http://www.code666.cn/view/05425f51
  1. public static string GetWebPageAsString(string url) {
  2.     HttpWebRequest httpWebRequest =(HttpWebRequest)WebRequest.Create(url);
  3.     // you may need these next two lines to prevent a .net bug
  4.     // System.IO.IOException : Unable to read data from the transport connection: The connection was closed.
  5.     // see http://support.microsoft.com/default.aspx?scid=kb;EN-US;915599
  6.     httpWebRequest.KeepAlive = false;
  7.     httpWebRequest.ProtocolVersion = HttpVersion.Version10;
  8.            
  9.     HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  10.     Stream stream = httpWebResponse.GetResponseStream();
  11.     StreamReader streamReader = new StreamReader(stream, Encoding.ASCII);
  12.     return streamReader.ReadToEnd();
  13. }
  14. //csharp/4824

回复 "C#抓取网页代码存在字符串里"

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

captcha