如何解决将睡眠功能放在 MSXML 请求中的何处?
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 在短时间内没有响应时,我会收到超时错误。因此,如果没有成功响应,我想在 this Q/A 中使用以下函数在 5 秒后终止请求,但我不知道将 asp_Wait(5) 放在哪里以及如何在 5 秒后取消请求?我应该在 o.send
或 o.send
行为同步之后立即放置 asp_Wait 吗?
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
解决方法
如果使用 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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。