Any way to get the html of the webpage even if the title is set to 404? Some pages still have text, and in my case I need to read that text.
Sample C # code for HTML:
public static string GetHtmlFromUri(string resource)
{
string html = string.Empty;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(resource);
using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
{
bool isSuccess = (int)resp.StatusCode < 299 && (int)resp.StatusCode >= 200;
if (isSuccess)
{
using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
{
html = reader.ReadToEnd();
}
}
}
return html;
}
And here is the page I created to check this for 404 errors: http://bypass.rd.to/headertest.php
If you look in the header, you will see that it is 404, but the text can be read. Now try to get the page in C # ...
MessageBox.Show(GetHtmlFromUri("http://bypass.rd.to/headertest.php"));
System.Net.WebException
= " : (404) ."
Source = "System"
StackTrace: at System.Net.HttpWebRequest.GetResponse()