获得HttpWebResponse请求的详细错误内容

try
{
    
}
catch (WebException ex)
{
    HttpWebResponse response = (HttpWebResponse)ex.Response;
    Console.WriteLine("Error code: {0}", response.StatusCode);

    using (Stream data = response.GetResponseStream())
    {
        using (StreamReader reader = new StreamReader(data))
        {
            string text = reader.ReadToEnd();
        }
    }
}

 

posted @ 2018-10-09 10:30  jamess  阅读(1785)  评论(0编辑  收藏  举报