关与WEBREQUEST和WEBRESPONSE两个类获取网页数据的问题!
我想请问,为什么用如下代码获得的网页数据总是和目标网页有一些出入,好像总是比目标网页要长,出现部分重复数据,还有一个问题就是用这段代码获得的网页数据是对于某些网站总是会返回500服务器内部错误???请各位帮忙解决!!!!
System.Net .WebRequest webrq=null;
System.Net.WebResponse webrs=null;
string result=null;
try
{
webrq=System.Net.WebRequest.Create (UrlRoot+this.NodeUrl );
webrs=webrq.GetResponse ();
System.IO.Stream stream=webrs.GetResponseStream();
byte[] buffer=new byte [webrs.ContentLength ];
while(
stream.Read (buffer,0,buffer.Length )!=0)
result+=System.Text .Encoding .GetEncoding ("GB2312").GetString (buffer);
stream.Close ();
webrs.Close ();
}
catch(Exception ex2)
{
return;
}
finally
{
if(webrs!=null)
webrs.Close ();
}//webrq.Timeout =10000;