K
Knoxy
Hi guys,
I've got this working but I have issues when there is any kind of c#
coding on the page that I'm trying to scrape (pages within my site -
its for a print page view basically), I get this error:
The remote server returned an error: (500) Internal Server Error
Now, I've stepped into the page that its calling, and it doesnt come
across an error. Any ideas? Code below:
private string ReadHtmlFromUrl (string url)
{
try
{
System.Net.WebRequest httpReq = System.Net.WebRequest.Create(url);
System.Net.WebResponse httpRes = httpReq.GetResponse();
byte [] buffer = new byte[1024];
System.Text.StringBuilder sb = new System.Text.StringBuilder();
while(httpRes.GetResponseStream().Read(buffer,0,buffer.Length) != 0)
{
sb.Append(System.Text.Encoding.UTF8.GetString(buffer));
}
httpRes.Close();
return sb.ToString();
}
catch (Exception ex)
{
return "";
}
}
Cheers,
Andrew
I've got this working but I have issues when there is any kind of c#
coding on the page that I'm trying to scrape (pages within my site -
its for a print page view basically), I get this error:
The remote server returned an error: (500) Internal Server Error
Now, I've stepped into the page that its calling, and it doesnt come
across an error. Any ideas? Code below:
private string ReadHtmlFromUrl (string url)
{
try
{
System.Net.WebRequest httpReq = System.Net.WebRequest.Create(url);
System.Net.WebResponse httpRes = httpReq.GetResponse();
byte [] buffer = new byte[1024];
System.Text.StringBuilder sb = new System.Text.StringBuilder();
while(httpRes.GetResponseStream().Read(buffer,0,buffer.Length) != 0)
{
sb.Append(System.Text.Encoding.UTF8.GetString(buffer));
}
httpRes.Close();
return sb.ToString();
}
catch (Exception ex)
{
return "";
}
}
Cheers,
Andrew