Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

vbscript - how to use MSXML2 setTimeouts to prevent timeout error?

I use the following function to check if a URL responds in a few seconds:

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

Instead of getting "active" or "inactive" I get the following error:

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

Footnote: The tested URL above buffers a big amount of text with no server error. Is it a special case and I need more code to handle this kind of response?

question from:https://stackoverflow.com/questions/65869073/how-to-use-msxml2-settimeouts-to-prevent-timeout-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

May be this can did the trick !

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...