GetResponseWithoutException
Allow to get the HttpWebResponse event if the request wasn't successful, in order, for example, to know what went wrong
Source
public static HttpWebResponse GetResponseWithoutException(this HttpWebRequest request)
{
try
{
return (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
HttpWebResponse response = ex.Response as HttpWebResponse;
if (response == null)
{
throw;
}
return response;
}
}
Example
var response = request.GetResponseWithoutException();
if (response.StatusCode == HttpStatusCode.OK)
{
// Request was successful
}
else if (response.StatusCode == HttpStatusCode.NotFound)
{
}