异步的Htt prequest在ASP中使用WinHttp.WinHtt prequest.5.1 [英] Asynchronous HttpRequest using WinHttp.WinHttpRequest.5.1 in ASP
问题描述
我试图让LINK FINDER和 2面临的问题
问题1(解决)的::无法获取重定向页面的网址
这是解决<一个href=\"http://stackoverflow.com/questions/20358654/serverxmlhttp-request-returing-data-but-not-returning-url-of-final-page-after-30\">REFERNCE通过使用LINK WinHttp.WinHtt prequest.5.1
问题2(未解)的::无法使用WinHttp.WinHtt prequest.5.1对象的活动或无回调异步请求
同步请求code 的
设置REQ =的CreateObject(WinHttp.WinHtt prequest.5.1)
req.openGET,网址,FALSE
req.setRequestHeader内容类型,应用程序/ x-WWW的形式urlen codeD
req.send的PostData
这是工作正常,但如果我有multuple要求,那么其抽空多的时间。
我曾尝试下面的的异步请求code 的,但得到的错误
设置REQ =的CreateObject(WinHttp.WinHtt prequest.5.1)
req.openGET,网址,TRUE
req.OnReadyStateChange = GetRef(req_OnReadyStateChange)
req.setRequestHeader内容类型,应用程序/ x-WWW的形式urlen codeD
req.send的PostData功能req_OnReadyStateChange
' 做一点事
结束功能
的 code 1 的
设置REQ =的CreateObject(WinHttp.WinHtt prequest.5.1,req_)
req.openGET,网址,TRUE
功能req__OnResponseFinished
' 做一点事
结束功能
req.setRequestHeader内容类型,应用程序/ x-WWW的形式urlen codeD
req.send的PostData
错误 - 远程服务器计算机不存在或不可用:'的CreateObject的
的 code 2 的
设置REQ =的CreateObject(WinHttp.WinHtt prequest.5.1)
req.openGET,网址,TRUE
req.OnResponseFinished = GetRef(req_OnResponseFinished)
功能req_OnResponseFinished
' 做一点事
结束功能
req.setRequestHeader内容类型,应用程序/ x-WWW的形式urlen codeD
req.send的PostData
错误:对象不支持此属性或方法:req.OnResponseFinished的
的 code 3 的
设置REQ =的CreateObject(WinHttp.WinHtt prequest.5.1)
req.openGET,网址,TRUE
req.OnReadyStateChange = GetRef(req_OnReadyStateChange)
req.setRequestHeader内容类型,应用程序/ x-WWW的形式urlen codeD
req.send的PostData
功能req_OnReadyStateChange
' 做一点事
结束功能
在微软的文档,他们被称为
的 WinHttp.WinHtt prequest.5.1 的有4个事件。
块引用>
- 的OnError
- OnResponseDataAvailable
- OnResponseFinished
- OnResponseStart
但我没有得到的例子如何使用此事件,也不是我能够在ASP中使用这些事件。
希望快速响应...
解决方案你尝试过用子,而不是一个函数,该函数req_OnReadyStateChange?
这是我使用的MSXML2.ServerXMLHTTP对象,这是工作的罚款的方式。没有任何理由,你为什么使用这个API的WinHTTP?
例如与MSXML2.ServerXMLHTTP:
&LT;%
昏暗的URL:URL =HTTP:// localhost的
昏暗为XmlHttp:设置为XmlHttp =的Server.CreateObject(MSXML2.ServerXMLHTTP)
XmlHttp.onreadystatechange = getRef(doHtt preadyStateChange)
XmlHttp.openGET,网址,真实
XmlHttp.send()子doHtt preadyStateChange
回复于XmlHttp.readyState
RESPONSE.WRITE&LT; BR&gt;中 选择的情况下XmlHttp.readyState
案例0UNINITIALIZED 案例1LOADING 案例2'受压 案例3互动 案例4竣工
的Response.Write完成
最终选择
分结束
%GT;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.
- OnError
- OnResponseDataAvailable
- OnResponseFinished
- OnResponseStart
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 %>
这篇关于异步的Htt prequest在ASP中使用WinHttp.WinHtt prequest.5.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!