Skip to content

Instantly share code, notes, and snippets.

@mikeobrien
Created December 5, 2012 15:11
Show Gist options
  • Save mikeobrien/4216340 to your computer and use it in GitHub Desktop.
Save mikeobrien/4216340 to your computer and use it in GitHub Desktop.
Get response extension
public static HttpWebResponse GetResponse(this HttpWebRequest request, bool throwHttpExceptions)
{
if (throwHttpExceptions) return (HttpWebResponse)request.GetResponse();
try
{
return (HttpWebResponse)request.GetResponse();
}
catch (WebException e)
{
var response = e.Response as HttpWebResponse;
if (response == null) throw;
return response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment