How To Get Error number in WebException Error?
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("site");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
int i = stream.ReadByte();
}
catch (WebException e)
{
//How To Get Error number in WebException Error?
}
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With