c# 4.0 - C# HttpWebRequest ignore HTTP 500 error -


i'm trying download page using webrequest class in c#4.0. reason page returns content correctly, http 500 internal error code.

request.endgetresponse(ar); 

when page returns http 500 or 404, method throws webexception. how can ignore this? know returns 500 still want read contents of page / response.

you can try / catch block catch exception , additional processing in case of http 404 or 500 errors looking @ response object exposed webexeption class.

try {     response = (httpwebresponse)request.endgetresponse(ar); } catch (system.net.webexception ex) {     response = (httpwebresponse)ex.response;      switch (response.statuscode)     {         case httpstatuscode.notfound: // 404             break;          case httpstatuscode.internalservererror: // 500             break;          default:             throw;     } } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -