7

为什么下面的代码在运行时会报 80004005 错误?我试图每 10 秒获取几个站点的状态......(给出的只是示例)。

'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
4

2 回答 2

13

首先,你必须改变

Http.Open "GET", site, True 

Http.Open "GET", site, False

因为如果调用是异步的,则不能Http.Status立即使用。Http.Send

此外,您应该使用

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

代替

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

因为普通 XMLHTTP 对象在重定向网站时存在问题(www.google.com 通常会将您重定向到另一个站点)。

于 2010-10-01T06:52:36.700 回答
1
Const ForWriting = 2

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

msgbox objHTTP.ResponseText
于 2018-06-28T11:02:14.740 回答