When you try to get the data from the site, an exception is thrown because the page is not found (your error 404) so you need to catch this exception and grab the data from the response stream.
So you'd need something like this:
string s;
try
{
s = client.DownloadString("http://www.404errorpages.com/something");
}
catch (WebException e)
{
if(e.Status == WebExceptionStatus.ProtocolError)
{
HttpWebResponse response = e.Response as HttpWebResponse;
if (response != null)
{
StreamReader sr = new StreamReader(e.Response.GetResponseStream());
s = sr.ReadToEnd();
}
}
}
console.WriteLine(s);
You might want to take a quick look over
this[
^] which should give you any info you might want on
HttpWebRequest
and
HttpWebResponse