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());
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…