Wednesday, August 1, 2012

Extract details from a WebException

try
{
    //Do something
}
catch (WebException ex)
{
    using (var stream = ex.Response.GetResponseStream())
    using (var reader = new StreamReader(stream))
    {
        string errormessage = reader.ReadToEnd();
    }
}
catch (Exception ex)
{
    //Do something
}