I am looking for some help about the method below which partly works.
The problem is that the data returned is truncated in that the
returned data has missing bytes near the beginning of the data. I am
using VS 2005 and C#.
Has anyone got any ideas?
public string getWebPage(stri ng url)
{
// add error handling
StringBuilder sb = new StringBuilder() ;
byte[] buf = new byte[8192];
try
{
HttpWebRequest request = (HttpWebRequest )WebRequest.Cre ate(url);
request.UserAge nt = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de-
DE;"+
"rv:1.7.5) Gecko/20041108 Firefox/1.0";
request.Timeout =20000;
HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();
Stream responseStream = response.GetRes ponseStream();
StreamReader myTextReader = new StreamReader(re sponseStream);
char[] strBuffer = new char[25];
myTextReader.Re adBlock(strBuff er,0,25);
string stringBuffer = new string(strBuffe r);
if (stringBuffer.I ndexOf("GIF8")>-1 ||
stringBuffer.In dexOf("JFIF")>-1)
{
// image found
return "image";
}
else
{
// this is a text page
}
string tempString = null;
int count = 0;
do
{
count = responseStream. Read(buf,0,buf. Length);
if (count!=0)
{
tempString=Enco ding.ASCII.GetS tring(buf,0,cou nt);
sb.Append(tempS tring);
}
}while (count>0);
}
catch (WebException e)
{
return "ZenoBot getWebPage web failed to fetch "+e.ToString(); ;
}
catch (Exception e)
{
return "ZenoBot getWebPage web failed to fetch "+e.ToString(); ;
}
return sb.ToString();
}
}
The problem is that the data returned is truncated in that the
returned data has missing bytes near the beginning of the data. I am
using VS 2005 and C#.
Has anyone got any ideas?
public string getWebPage(stri ng url)
{
// add error handling
StringBuilder sb = new StringBuilder() ;
byte[] buf = new byte[8192];
try
{
HttpWebRequest request = (HttpWebRequest )WebRequest.Cre ate(url);
request.UserAge nt = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de-
DE;"+
"rv:1.7.5) Gecko/20041108 Firefox/1.0";
request.Timeout =20000;
HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();
Stream responseStream = response.GetRes ponseStream();
StreamReader myTextReader = new StreamReader(re sponseStream);
char[] strBuffer = new char[25];
myTextReader.Re adBlock(strBuff er,0,25);
string stringBuffer = new string(strBuffe r);
if (stringBuffer.I ndexOf("GIF8")>-1 ||
stringBuffer.In dexOf("JFIF")>-1)
{
// image found
return "image";
}
else
{
// this is a text page
}
string tempString = null;
int count = 0;
do
{
count = responseStream. Read(buf,0,buf. Length);
if (count!=0)
{
tempString=Enco ding.ASCII.GetS tring(buf,0,cou nt);
sb.Append(tempS tring);
}
}while (count>0);
}
catch (WebException e)
{
return "ZenoBot getWebPage web failed to fetch "+e.ToString(); ;
}
catch (Exception e)
{
return "ZenoBot getWebPage web failed to fetch "+e.ToString(); ;
}
return sb.ToString();
}
}
Comment