我在网上找到C#获取网页内容的代码:http://qilinwuxian.blogchina.com/1438711.html
在获取小网页的时候没什么问题,但是网页比较大时文本会截断,用StreamReader就没有什么问题,不知道是为什么?
用代码中的5,6,7行的方法,count的值明显小于buf的长度,为什么不能读完全呢?

 1用stream.Read不能完整读取内容的问题。HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create("http://www.cnblogs.com/rss.aspx?id=-1");
 2用stream.Read不能完整读取内容的问题。HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
 3用stream.Read不能完整读取内容的问题。System.IO.Stream stream = HttpWResp.GetResponseStream();
 4用stream.Read不能完整读取内容的问题。
 5用stream.Read不能完整读取内容的问题。//byte[] buf = new byte[38192]; 
 6用stream.Read不能完整读取内容的问题。//int count = stream.Read(buf,0,buf.Length);
 7用stream.Read不能完整读取内容的问题。//txtResult.Text = System.Text.Encoding.UTF8.GetString(buf, 0,count); 
 8用stream.Read不能完整读取内容的问题。
 9用stream.Read不能完整读取内容的问题。System.IO.StreamReader sr = new System.IO.StreamReader(stream,System.Text.Encoding.UTF8);
10用stream.Read不能完整读取内容的问题。txtXML.Text =  sr.ReadToEnd();

相关文章:

  • 2021-12-04
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
  • 2022-02-21
猜你喜欢
  • 2021-10-24
  • 2018-12-24
  • 2021-07-24
  • 2022-03-03
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案