Question Detecting 'Cannot find server'

gchq

Well-known member
Joined
Dec 14, 2007
Messages
168
Programming Experience
10+
Hi there

I can validate a URL by using HttpWebRequest and HttpWebResponse.

I would like to go one stage further and ensure that the actual page is valid and not returning 'Cannot find server or DNS Error'

The main problem is that (for this - video stream pages) it's an IP address that is specified, not a domain name - so a DNS check is also out!

Any ideas

Thanks
 
This seems to work (checking for valid html tags)


VB.NET:
Public Function DetectPageDisplay(ByVal URL As String) As Boolean
        Dim sStream As Stream
        Dim URLReq As HttpWebRequest
        Dim URLRes As HttpWebResponse
        Try
            URLReq = WebRequest.Create(URL)
            URLRes = URLReq.GetResponse()
            sStream = URLRes.GetResponseStream()
            Dim reader As String = New StreamReader(sStream).ReadToEnd()

            If Not URLRes Is Nothing Then
                URLRes.Close()
            End If
            If Not reader.ToLower.Contains("<html>") Then
                'Url is valid, but page contains no html
                Return False
            Else
                Return True
            End If
        Catch ex As Exception
            'Url not valid
            Return False
        End Try
    End Function
 
Back
Top