我试图使链接查找器和面临2个问题
问题1(已解决)::无法获取重定向页面的url
这是通过使用WinHttp.WinHttpRequest.51解决的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
在微软的文档中,他们提到WinHttp.WinHttpRequest.5.1有4个事件。
- OnError
- OnResponseData可用
- 响应完成
- 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
%>