【问题标题】:how to use MSXML2 setTimeouts to prevent timeout error?如何使用 MSXML2 setTimeouts 来防止超时错误?
【发布时间】:2021-04-28 07:58:00
【问题描述】:

我使用以下函数来检查 URL 是否在几秒钟内响应:

function testUrl(url)
    Set xmlDOM = CreateObject("MSXML2.ServerXMLHTTP.6.0")
    xmlDOM.Open "GET", url, False
    xmlDOM.setTimeouts 1000,1000,1000,1000
    testUrl=xmlDOM.Send
end function

if testUrl("http://khabarfoori.com/rss/mm") then 
    responsw.write "active" 
    else 
    response.write "inactive"
end if

我得到以下错误,而不是 "active""inactive"

>     msxml6.dll error '80072ee2'
>     The operation timed out

脚注:上面测试的 URL 缓冲了大量文本,没有服务器错误。是不是特殊情况,我需要更多代码来处理这种响应?

【问题讨论】:

    标签: vbscript timeout msxml2


    【解决方案1】:

    也许这可以解决问题!

    feed = "http://khabarfoori.com/rss/mm"
    Set req = CreateObject("Msxml2.ServerXMLHTTP.6.0")
    req.Open "GET", feed, False
    req.Send
    Set xml = CreateObject("Msxml2.DOMDocument")
    xml.loadXml(req.responseText)
    First_Title = xml.getElementsByTagName("channel/item/title")(0).Text
    
    If Len(First_Title) <> 0 Then
        MsgBox "active"
        MsgBox First_Title
    else 
        MsgBox"inactive"
    End If
    

    【讨论】:

    • 这会在目标 url 没有响应或有错误时导致错误
    猜你喜欢
    • 1970-01-01
    • 2015-07-13
    • 1970-01-01
    • 2012-02-25
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多