/* BeejBløg */

Oct 5, 2013 - 1 minute read - Comments -

HttpWebResponse from WebException

 1 2 3 4 5 6 7 8 91011
using (var response = (HttpWebResponse)((Func)(() =>
{
  try { return(request.GetResponse());}
  catch (WebException ex) { return(ex.Response); }
}))()) //<-- too funny
using (var responseStream = response.GetResponseStream())
// ReSharper disable once AssignNullToNotNullAttribute
using (var readStream = new StreamReader(responseStream, Encoding.UTF8))
{
  return String.Format("{0} {1}. {2}", (int)response.StatusCode, response.StatusCode, readStream.ReadToEnd());
}