我正在使用.Net与Web服务器进行通信。Web服务器抛出500内部服务器错误并编写了详细的错误消息。
我试图读取从Web异常接收到的错误消息,但却得到另一个Web异常。为什么会抛出第二个WebException?
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());
}
}