none
[Help] Check url RRS feed

  • Question

  • Hello friends,

    I want to check that a url responds, if this responds I want a message to be displayed saying ok, otherwise say for example error.

    How can I do this?
    Tuesday, May 23, 2017 11:02 AM

Answers

  • Keep in mind that requests are independent of one another, so just because one request succeeds it doesn't mean the next one will.

            Try
                Dim request As HttpWebRequest = HttpWebRequest.Create("http://www.msn.com")
                Dim response As HttpWebResponse = CType(request.GetResponse, HttpWebResponse)
                If ((response Is Nothing) OrElse (response.StatusCode <> HttpStatusCode.OK)) Then
                    Console.WriteLine("No response from web site")
                Else
                    Console.WriteLine("Web site responded")
                End If
            Catch ex As Exception
                Console.WriteLine(ex.Message)
            End Try


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by Symantecc Tuesday, May 23, 2017 8:47 PM
    Tuesday, May 23, 2017 12:36 PM

All replies

  • Symantec,

    Can you describe what you mean with responds, because when it gives a 404 it is in fact responding. 

    Here how to read a page (document) using Process Start as shown on our website, but probably there is a better way which fits more to your needs.

    http://www.vb-tips.com/Shell.aspx


    Success
    Cor


    Tuesday, May 23, 2017 11:31 AM
  • Keep in mind that requests are independent of one another, so just because one request succeeds it doesn't mean the next one will.

            Try
                Dim request As HttpWebRequest = HttpWebRequest.Create("http://www.msn.com")
                Dim response As HttpWebResponse = CType(request.GetResponse, HttpWebResponse)
                If ((response Is Nothing) OrElse (response.StatusCode <> HttpStatusCode.OK)) Then
                    Console.WriteLine("No response from web site")
                Else
                    Console.WriteLine("Web site responded")
                End If
            Catch ex As Exception
                Console.WriteLine(ex.Message)
            End Try


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by Symantecc Tuesday, May 23, 2017 8:47 PM
    Tuesday, May 23, 2017 12:36 PM


    1. Paul ~~~~ Microsoft MVP (Visual Basic)


    Hi Paul, 

    Maybe a more real live sample and use in your code this one. 

    Dim request As HttpWebRequest = HttpWebRequest.Create("https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral") 
    :-)


    Success
    Cor

    Tuesday, May 23, 2017 1:44 PM


    1. Paul ~~~~ Microsoft MVP (Visual Basic)


    Hi Paul, 

    Maybe a more real live sample and use in your code this one. 

    Dim request As HttpWebRequest = HttpWebRequest.Create("https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral") 
    :-)


    Success
    Cor


    LOL. You might have to actually check to see what was returned for this forum, even if the request was successful. ;-)

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Tuesday, May 23, 2017 2:32 PM