Eugene
Eugene

Reputation: 11535

VBS Microsoft.XMLHTTP status

Why does the following code give a 80004005 error when run? I'm trying to get the status of several sites every 10 seconds...(the ones given are examples).

'http://www.sebsworld.net/information/?page=VBScript-URL
'http://www.paulsadowski.com/wsh/xmlhttp.htm

'the array of sites
sites = Array("http://www.google.com/","http://en.wikipedia.org/wiki/Main_Page")

While(True)
    For Each site In sites

        'Get site status
        Set Http = WScript.CreateObject("Microsoft.XMLHTTP")
        Http.Open "GET", site, True
        Http.Send

        If(Http.Status <> 200) Then 'site isn't 200
            MsgBox "The site at " & vbNewLine & site & vbNewLine & "has status: " & Http.Status
        End If
    Next

    WScript.Sleep(10)'Sleep 10 seconds
Wend

Upvotes: 7

Views: 28275

Answers (2)

Asitha Yomal
Asitha Yomal

Reputation: 675

Const ForWriting = 2

strURL="http://asithayomal.1apps.com"
Set objHTTP = CreateObject("MSXML2.XMLHTTP") 
Call objHTTP.Open("GET", strURL, FALSE) 
objHTTP.Send

msgbox objHTTP.ResponseText

Upvotes: 1

user128300
user128300

Reputation:

First, you have to change

Http.Open "GET", site, True 

to

Http.Open "GET", site, False

because you cannot use Http.Status immediately after Http.Send if the call is asynchronous.

Furthermore, you shoud use

Set Http = WScript.CreateObject("MSXML2.ServerXMLHTTP") 

instead of

Set Http = WScript.CreateObject("Microsoft.XMLHTTP")

because the normal XMLHTTP object has problems with redirected web sites (www.google.com normally redirects you to another site).

Upvotes: 15

Related Questions