Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to validate live webpage

Status
Not open for further replies.

JesOakley

Programmer
Jan 21, 2008
42
0
0
GB
Hi folks,

I've scoured the net trying to find something that does this, but I can't find anything that seems to work. My basic problem is that I'm not a vbscript programmer and don't really know whether the values I'm passing to the functions are correct and what return values I should expect. If anyone can help me or just point me at a decent, comprehensive and explanatory resource I would appreciate it.

If I comment out the 'on error resume next' line, I get the error message WinHttp.WinHttpRequest: A connection with the server could not be established. I hasten to add that a normal IE7 call to Google works fine!
Code:
Dim strWebsite
strWebsite = "[URL unfurl="true"]http://www.google.co.uk/"[/URL]

If TestSite(strWebsite) Then
    WScript.Echo "Web site " & strWebsite & " is up and running!"
Else
    WScript.Echo "Web site " & strWebsite & " is down!!!"
End If

Function TestSite(strWebsite)
    Dim intStatus, objHTTP
    Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

    objHTTP.Open "GET", strWebsite, False
    objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)"

    On Error Resume Next
    objHTTP.Send
    intStatus = objHTTP.Status
	On Error Goto 0

    If intStatus = 200 Then
        TestSite = True
    Else
        TestSite = False
		WScript.Echo "Status: " & cStr(intStatus)
    End If

    Set objHTTP = Nothing
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top