HttpWebRequest 请求时,服务器会返回500 501这些错误 并包含错误信息,通过如下代码可以拿到错误信息
代码语言:javascript复制HttpWebResponse res;
try
{
res = (HttpWebResponse)req.GetResponse();
}
catch (WebException ex)
{
res = (HttpWebResponse)ex.Response;
}
StreamReader sr = new StreamReader(res.GetResponseStream(), strEncode);
strHtml = sr.ReadToEnd();