Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

vbscript - How to handle server address not resolved in XMLHTTP request?

I used the following code to check if a RSS url responds in 5 seconds so I can consume the RSS feed however trying to open the URL causes error when the target URL could not be resolved. What more I need rather than waitForResponse to also handle this situation?

    Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")
    http.open "POST", "https://persiadigest.com/fa/rss/8", True
    http.send
    
    If http.waitForResponse(5) Then
        body=http.responsetext
    Else
        response.write "Target url is not responding"
    End If
    Set http = Nothing

Error details:

msxml3.dll error '80072ee7' The server name or address could not be resolved

question from:https://stackoverflow.com/questions/65870869/how-to-handle-server-address-not-resolved-in-xmlhttp-request

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

1 Answer

0 votes
by (71.8m points)

A simple function that ignores errors would work.

Function WaitIgnoreError(ByRef requestObject, timeout)
    On Error Resume Next
    WaitIgnoreError  = requestObject.WaitForResponse(timeout)
End Function

Usage:

If WaitIgnoreError(http, 5) Then
    body = http.responsetext
Else
    response.write "Target url is not responding"
End If

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...