HttpStatusCode 404

D

Dan

This status represents "Page Not Found". However, when I execute the code
below with a purposely bogus URL, GetResponse throws an error before I can
retrieve the 404 status. I've been told on this group that this is the way
it's supposed to work. If that's so, why is 404 included in the
HttpStatusCode enumeration at all; you can never retrieve it.

Dan

try
{
HttpWebResponse response = (HttpWebResponse) m_request.GetResponse();

Console.WriteLine("Status Code = " + response.StatusCode);
}
catch(System.Net.WebException ex)
{
Console.WriteLine(ex.ToString()); // Returns "The remote server returned an
error: (404) Not Found"
}
 
K

Kevin Spencer

retrieve the 404 status. I've been told on this group that this is the
way
it's supposed to work. If that's so, why is 404 included in the
HttpStatusCode enumeration at all; you can never retrieve it.

Because not every return code is 404. Occasionally, a page is found.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
D

Dan

??? I'm not sure we're communicating here. The question is: why can you not
retrieve the status code? The exception is thrown before you even get the
chance.
 
H

Hugo Wetterberg

You can retrieve the status code. Not when it's a 404, but on a number
of other occasions. As to why it's included, probably for the sake of
completeness. It just might be used in other places where there
actually is a use for the 404 entry.
/Hugo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top