I was trying to make LINK FINDER and facing 2 issue
Issue 1 (Resolved) :: Unable to get url of redirected page
This was resolved REFERNCE LINK by using WinHttp.WinHttpRequest.5.1
Issue 2 (Unsolved) :: unable to use WinHttp.WinHttpRequest.5.1 object EVENTS Or no callback to asynchronous request
Synchronous request code
Set req = CreateObject("WinHttp.WinHttpRequest.5.1")
req.open "GET", url, FALSE
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.send PostData
This is working fine but if I have multuple request , then its taking to much time.
I have tried following Asynchronous request code but get error
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
Code 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
ERROR - The remote server machine does not exist or is unavailable: 'CreateObject'
Code 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
ERROR : Object doesn't support this property or method: 'req.OnResponseFinished
Code 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.
But i didn't got example of how to use this event, nor i am able to use these event in ASP.
Hope for quick response...
have you tried using a Sub instead of a function for that "req_OnReadyStateChange"?
by the way i am using the MSXML2.ServerXMLHTTP object and this is working fine. is there any reason why you are using this WinHttp API?
example with 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
%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With