vbscript使用IE错误发送GET请求

时间:2013-03-25 11:07:46

标签: windows vbscript

我在下面的vbscript需要发送GET请求,然后注销当前用户。我们的想法是用这个脚本替换默认的“注销”开始菜单项。

当我使用cscript运行它时,它会在第9行引发错误

HTTPGet = IE.document.documentelement.outerhtml

我不明白什么是错的。也许我应该在注销用户之前等待接收响应,但由于上面的行似乎不起作用,我立即注销。

TOKEN = "xxxxx"
Set IE = CreateObject("InternetExplorer.Application")
IE.visible = 0
IE.navigate "https://something.com/?action=create&token=" & TOKEN
Do While IE.Busy
   WScript.Sleep 200  ' see the above notice of change
   Exit Do                  ' prevents script host from going crazy waiting for IE
loop
HTTPGet = IE.document.documentelement.outerhtml
IE.quit
Set IE = Nothing

'WScript.Echo HTTPGet   'good for debugging. shows what you got back.

Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "C:\WINDOWS\system32\shutdown.exe -l"

如果重要的话,这只适用于Windows XP,只适用于IE 8。

1 个答案:

答案 0 :(得分:1)

试试这段代码:

Set IE = CreateObject("InternetExplorer.Application")
IE.visible = 0
IE.navigate "https://host/?a=" & TOKEN
i = 1
Do While (IE.readyState <> 4)
   WScript.Sleep 1000  ' see the above notice of change
   i = i + 1
   If (i > 10) Then
      Exit Do
   End If
loop
HTTPGet = IE.document.documentElement.outerHTML
IE.Quit()
Set IE = Nothing