locked
How to detect error response when using HttpWebRequest RRS feed

  • Question

  • User-1518977582 posted

     I'm using vb.net and VS 2005 for this.

    I am downloading pdf files form a remote server using HttpWebRequest. Occassionally I request a document that has been removed and I get a 404 error. This stops my application from downloading when I want to log it and continue. Can you tell me how I can capture a 404 error and continue processing beyond it?

     

    Thanks

    Friday, August 21, 2009 11:54 PM

Answers

  • User214117797 posted

    I am downloading pdf files form a remote server using HttpWebRequest. Occassionally I request a document that has been removed and I get a 404 error. This stops my application from downloading when I want to log it and continue. Can you tell me how I can capture a 404 error and continue processing beyond it?

    You can check the StatusCode property of the HttpResponse object you get back when invoking the HttpRequest object.

                WebRequest req = HttpWebRequest.Create("http://www.hotmail.com");
                WebResponse res = req.GetResponse();
                HttpWebResponse response = (HttpWebResponse)res;
                if (response.StatusCode == HttpStatusCode.NotFound)
                {
                   // 404 error
                }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 22, 2009 3:07 AM