为什么下面的代码运行时会出现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
最佳答案
首先,你必须改变
Http.Open "GET", site, True
到
Http.Open "GET", site, False
因为如果调用是异步的,则无法在 Http.Send
之后立即使用 Http.Status
。
此外,您应该使用
Set Http = WScript.CreateObject("MSXML2.ServerXMLHTTP")
而不是
Set Http = WScript.CreateObject("Microsoft.XMLHTTP")
因为普通的 XMLHTTP 对象在重定向网站时存在问题(www.google.com 通常会将您重定向到另一个网站)。
关于vbscript - VBS Microsoft.XMLHTTP 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3836130/