سؤال

I have the following method in my create.asp page:

Public Function read(url)

    Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
    Set xml = Server.CreateObject("Microsoft.XMLDOM")

    xmlHttp.Open "GET", url, False, PROXY_USERNAME, PROXY_PASSWORD
    xmlHttp.SetProxy 2, PROXY
    xmlHttp.SetTimeouts 0, 0, 0, 0
    xmlHttp.Send


    xml.Async = False
    xml.SetProperty "ServerHTTPRequest", True
    xml.ValidateOnParse = True

    xml.Load xmlHttp.ResponseXml

    Set read = xml

    Set xmlHttp = Nothing
    Set xml = Nothing
End Function

The function works 9 times out of 10.

Problem: In rare occasions, it gives me a timeout error. For this reason, I have set xmlHttp.Timeouts to infinity. I have also tried using On error statements, but that does not resolve the issue.

Question: *How do I execute the function from the start if it gives me any kind of error? * The only error I have come across is the timeout error when it tries to execute xmlHttp.Send.

Any other possible solution would also be appreciated.

هل كانت مفيدة؟

المحلول

Rather than a code problem, its most likely an issue with the proxy server.

If you want to be able to retry you can;

dim result
for i = 1 to 3 '//3 attempts
    set result = read("http://bla.bla")
    if (not result is nothing) then exit for
next

if (result is nothing) then
    '//repeatedly failed ...
else
    '//got a dom doc
end if

Public Function read(url)
    Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
    Set xml = CreateObject("Microsoft.XMLDOM")

    on error resume next

    xmlHttp.Open "GET", url, False
    xmlHttp.Send
    xml.Async = False
    xml.SetProperty "ServerHTTPRequest", True
    xml.ValidateOnParse = True
    xml.Load xmlHttp.ResponseXml

    if (err.number = 0) then
        set read = xml
     else
        set read = nothing
     end if

    on error goto 0
    Set xmlHttp = Nothing
    Set xml = Nothing
End Function
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top