HttpWebResponse res = null;
WebResponse response = null;
try
{
WebResponse response = webRequest.GetResponse();
}
catch (WebException ex1)
{
res = (HttpWebResponse)ex1.Response;
}
finally
{
StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
string strhtml = sr.ReadToEnd();
HttpContext.Current.Response.Write(strhtml);
}
当获取服务器响应出错时,捕捉错误,最终打印出错误即可。
您可能感兴趣的文章: