用stream.Read不能完整读取内容的问题。
2005-06-28 16:37
288 查看
我在网上找到C#获取网页内容的代码:http://qilinwuxian.blogchina.com/1438711.html
在获取小网页的时候没什么问题,但是网页比较大时文本会截断,用StreamReader就没有什么问题,不知道是为什么?
用代码中的5,6,7行的方法,count的值明显小于buf的长度,为什么不能读完全呢?
1HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create("http://www.cnblogs.com/rss.aspx?id=-1");
2HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
3System.IO.Stream stream = HttpWResp.GetResponseStream();
4
5//byte[] buf = new byte[38192];
6//int count = stream.Read(buf,0,buf.Length);
7//txtResult.Text = System.Text.Encoding.UTF8.GetString(buf, 0,count);
8
9System.IO.StreamReader sr = new System.IO.StreamReader(stream,System.Text.Encoding.UTF8);
10txtXML.Text = sr.ReadToEnd();
在获取小网页的时候没什么问题,但是网页比较大时文本会截断,用StreamReader就没有什么问题,不知道是为什么?
用代码中的5,6,7行的方法,count的值明显小于buf的长度,为什么不能读完全呢?
1HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create("http://www.cnblogs.com/rss.aspx?id=-1");
2HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
3System.IO.Stream stream = HttpWResp.GetResponseStream();
4
5//byte[] buf = new byte[38192];
6//int count = stream.Read(buf,0,buf.Length);
7//txtResult.Text = System.Text.Encoding.UTF8.GetString(buf, 0,count);
8
9System.IO.StreamReader sr = new System.IO.StreamReader(stream,System.Text.Encoding.UTF8);
10txtXML.Text = sr.ReadToEnd();
相关文章推荐
- 黑马程序员之C#学习笔记:使用Stream.BeginRead方法读取FileStream的流内容
- 怎么解决jsoup不能完整获取响应内容的问题
- 用sax读取XML时不能读取换行符号后面的内容的问题
- c#.net不能完全读取Excel内容的问题
- StreamReader缓冲引起BaseStream.Position不能反映当前Read位置的问题
- StreamReader缓冲引起BaseStream.Position不能反映当前Read位置的问题
- 利用fopen的fread和ifstream的read来读取txt文件的全部内容
- ASP .NET readonly texbox 后台不能读取问题的解决办法
- ifstream,fstream 读写文件问题,read读取字节不够
- 关于自适应屏幕,设置子元素浮动,父div不能包裹子div,子元素中内容溢出的问题。
- 输入框的value不能显示完整日期格式的问题
- fsockopen用feof读取http响应内容的一些问题
- vc中ifstream ofstream不能读取带有中文路径
- 使用InternetReadFile时要注意读取完整数据
- ubunt下c库函数fread不能读取的问题
- !!!!高分求教ReadProcessMemory读取内存.有关内存偏移量的问题!
- 解决fstream.open()不能正确读取中文路径的问题
- XP局域网访问无权限、不能互相访问问题的完整解决方案
- 解决友坚恒天4412不能读取U盘的问题
- 解决packet tracer不能复制CLI内容的问题