通过经典asp中的Vb脚本从错误/超时开始执行函数

发布于 2024-12-05 03:08:33 字数 855 浏览 8 评论 0原文

我的 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时出现超时错误。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

池予 2024-12-12 03:08:33

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

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

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文