首页 > Web开发 > 详细

HttpWebRequest 在出错时获取response内容

时间:2017-12-03 16:12:07      阅读:224      评论:0      收藏:0      [点我收藏+]

HttpWebRequest 请求时,服务器会返回500  501这些错误 并包含错误信息,通过如下代码可以拿到错误信息

HttpWebResponse res;
try
{
res = (HttpWebResponse)req.GetResponse();
}
catch (WebException ex)
{
res = (HttpWebResponse)ex.Response;
}
StreamReader sr = new StreamReader(res.GetResponseStream(), strEncode);
strHtml = sr.ReadToEnd();

HttpWebRequest 在出错时获取response内容

原文:http://www.cnblogs.com/bfyx/p/7966239.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!