C# HttpWebRequest ignore HTTP 500 error
问题 I'm trying to download a page using the WebRequest class in C#4.0. For some reason this page returns all the content correctly, but with a HTTP 500 internal error code. Request.EndGetResponse(ar); When the page returns HTTP 500 or 404, this method throws a WebException. How can I ignore this? I know it returns 500 but I still want to read the contents of the page / response. 回答1: You can a try / catch block to catch the exception and do additional processing in case of http 404 or 500 errors