2

我使用以下函数来检查 RSS url 是否健康,然后使用它:

function testUrl(url)
    testUrl=0
    Set o = CreateObject("MSXML2.XMLHTTP")
    on error resume next
    o.open "GET", url, false
    o.send
    if o.Status = 200 then testUrl = 1
    on error goto 0
    set o=nothing
end function

但是,当目标 URL 在短时间内没有响应时,我会收到超时错误。因此,如果没有成功响应,我想在此 Q/A中使用以下函数在5 秒后终止请求,但我不知道将 asp_Wait(5) 放在哪里以及如何在 5 秒后取消请求?我应该把 asp_Wait 放在 or 同步之后o.sendo.send

Function asp_Wait(nMilliseconds)
  Dim oShell
  Set oShell= Server.CreateObject("WScript.Shell")
  Call oShell.run("ping 1.1.1.1 -n 1 -w " & nMilliseconds,1,TRUE) 
End Function
4

1 回答 1

1

如果使用 WinHTTPRequest 对象,您可以调用WaitForResponse方法。

Set o = CreateObject("MSXML2.XMLHTTP")
o.open "GET", url, true 'async request
o.send
If o.waitForResponse(5) Then 'wait 5 sec
   ...
Else 'wait timeout exceeded
   ...
End If
于 2021-01-25T22:24:19.937 回答