gpt4 book ai didi

在ASP中使用WinHttp.WinHttpRequest.5.1的异步HttpRequest

转载 作者:行者123 更新时间:2023-12-04 03:07:02 26 4
gpt4 key购买 nike

我试图使LINK FINDER和面临2个问题

问题1(已解决)::无法获取重定向页面的URL

通过使用 WinHttp.WinHttpRequest.5.1 解决了REFERNCE LINK

问题2(未解决)::无法使用WinHttp.WinHttpRequest.5.1对象事件或没有对异步请求的回调

同步请求代码

Set req = CreateObject("WinHttp.WinHttpRequest.5.1")
req.open "GET", url, FALSE
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.send PostData

这工作正常,但是如果我有多个请求,那么它会花费很多时间。

我已尝试遵循 异​​步请求代码,但收到错误
Set req = CreateObject("WinHttp.WinHttpRequest.5.1")
req.open "GET", url, TRUE
req.OnReadyStateChange = GetRef("req_OnReadyStateChange")
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.send PostData

Function req_OnReadyStateChange
' do something
End Function

代码1
Set req = CreateObject("WinHttp.WinHttpRequest.5.1","req_")
req.open "GET", url, TRUE
Function req__OnResponseFinished
' do something
End Function
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.send PostData

错误-远程服务器计算机不存在或不可用:'CreateObject'

代码2
Set req = CreateObject("WinHttp.WinHttpRequest.5.1")
req.open "GET", url, TRUE
req.OnResponseFinished = GetRef("req_OnResponseFinished")
Function req_OnResponseFinished
' do something
End Function
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.send PostData

错误:对象不支持此属性或方法:'req.OnResponseFinished

代码3
Set req = CreateObject("WinHttp.WinHttpRequest.5.1")
req.open "GET", url, TRUE
req.OnReadyStateChange = GetRef("req_OnReadyStateChange")
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.send PostData
Function req_OnReadyStateChange
' do something
End Function

In microsoft documentation, they have referred WinHttp.WinHttpRequest.5.1 have 4 event.


  • OnError
  • OnResponseData可用
  • OnResponse已完成
  • OnResponseStart

  • 但是我没有如何使用此事件的示例,也无法在ASP中使用这些事件。

    希望快速回应...

    最佳答案

    您是否尝试过使用Sub代替该“req_OnReadyStateChange”函数?

    顺便说一句,我正在使用MSXML2.ServerXMLHTTP对象,这工作正常。有什么理由要使用此WinHttp API?

    MSXML2.ServerXMLHTTP的示例:

    <%
    dim url : url = "http://localhost"
    dim XmlHttp : set XmlHttp = server.createobject("MSXML2.ServerXMLHTTP")
    XmlHttp.onreadystatechange = getRef("doHttpReadyStateChange")
    XmlHttp.open "GET", url, true
    XmlHttp.send()

    sub doHttpReadyStateChange
    response.write XmlHttp.readyState
    response.write "<br>"

    select case XmlHttp.readyState
    case 0 'UNINITIALIZED

    case 1 'LOADING

    case 2 'LOADED

    case 3 'INTERACTIVE

    case 4 'COMPLETED
    response.write "Done"
    end select
    end sub
    %>

    关于在ASP中使用WinHttp.WinHttpRequest.5.1的异步HttpRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20552183/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com