我试图制作LINK FINDER和面临2个问题
问题1(已解决) ::无法获取重定向页面的网址
使用 WinHttp.WinHttpRequest.5.1
解决了这个问题REFERNCE LINK问题2(未解决) ::无法使用WinHttp.WinHttpRequest.5.1对象 EVENTS 或者没有回调异步请求
同步请求代码
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个事件。
但我没有得到如何使用此事件的示例,也无法在ASP中使用这些事件。
希望快速回复...
答案 0 :(得分:3)
您是否尝试过使用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
%>