How To Get Error number in WebException Error?
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(\"site\");
HttpWebResponse response
For Get Error Number:
catch(System.Net.WebException e)
{
int errorNumber = (int)e.Status;
}
You could try to parse the message, but there isn't always an error number. A timeout for example doesn't result in an HTTP error code.
You can't do that because WebException(s)
don't have error numbers. You can define your own error numbers if that's what you want/need to do.
Here's the documentation You can get Status, Message, StackTrace, etc, etc.
You'll want to run a test to make sure that it was a ProtocolError
:
if (e.Status == WebExceptionStatus.ProtocolError)
{
Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode);
Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription);
}