使用HttpWebRequest出错时获取详细的错误信息:
try { //HttpWebRequest 相关代码 } catch(WebException ex) { HttpWebResponse res = ex.Response as HttpWebResponse; string strError=""; if (res.StatusCode == HttpStatusCode.InternalServerError) { Stream s = res.GetResponseStream(); StreamReader objReader = new StreamReader(s, System.Text.Encoding.UTF8); strError = objReader.ReadToEnd(); objReader.Close(); } else { strError = ex.Message; } //打印strError }