1

我的create.asp页面中有以下方法:

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

该功能在 10 次中工作 9 次。

问题:在极少数情况下,它会给我一个超时错误。出于这个原因,我设置xmlHttp.Timeouts为无穷大。我也尝试过使用On error语句,但这并不能解决问题。

问题:*如果它给我任何类型的错误,我如何从一开始就执行该函数?*我遇到的唯一错误是它尝试执行时的超时错误xmlHttp.Send

任何其他可能的解决方案也将受到赞赏。

4

1 回答 1

2

与其说是代码问题,不如说是代理服务器的问题。

如果您希望能够重试,则可以;

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
于 2011-09-16T13:46:47.547 回答