I'm communicating with a web server from .Net. The web server throws a 500 internal server error and writes a detailed error message.
I'm trying to read the error message that is received from a web exception, but getting another web exception. Why is the second WebException thrown?
try
{
var webResponse = (HttpWebResponse)webRequest.GetResponse();
}
catch (WebException e)
{
if (e.Status == WebExceptionStatus.ProtocolError)
{
// the next line throws a web exception
Console.WriteLine(new StreamReader(e.Response.GetResponseStream()).ReadToEnd());
}
}