1

When I try to get a nonexistent page, or use an invalid HTTP method, HttpWebRequest.GetResponse() throws a System.Net.WebException, with a Status property of ProtocolError. In its Message property I can see the HTTP status code in parentheses. Fine. But I don't see an integer StatusCode property. Do I really have to parse the Message property to get it?

1 Answer 1

5

From the WebException.Status MSDN page:

((HttpWebResponse)your_exception.Response).StatusCode

The StatusCode property will give you an enum that maps to the regular status codes from the HTTP spec.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.