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
Post a Comment