HttpWebResponse returns 404 error

How to allow Httpwebresponse to ignore 404 error and continue it? This is easier than looking for exceptions in the input, as it happens very rarely when this happens.

+4
source share
3 answers

I assume you have a line somewhere in your code, for example:

HttpWebResponse response = request.GetResponse() as HttpWebResponse; 

Just replace it with the following:

 HttpWebResponse response; try { response = request.GetResponse() as HttpWebResponse; } catch (WebException ex) { response = ex.Response as HttpWebResponse; } 
+28
source
  try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://mysite.com"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); } catch(WebException ex) { HttpWebResponse webResponse = (HttpWebResponse)ex.Response; if (webResponse.StatusCode == HttpStatusCode.NotFound) { //Handle 404 Error... } } 
+10
source

If you look at the properties of the resulting WebException, you will see the Response property. Is this what you are looking for?

0
source

All Articles