有关 WinHttp.WinHttpRequest.5.1 事件函数!!

遇到了问题?请先进行搜索(中文和英文),然后在此提问

Moderators: tmplinshi, arcticir

wzxiaodu
Posts: 12
Joined: 30 Nov 2013, 09:42

有关 WinHttp.WinHttpRequest.5.1 事件函数!!

30 Mar 2014, 03:15

对于 WinHttp.WinHttpRequest.5.1
如何用到它的事件函数
比如:
void OnResponseDataAvailable(
[in] SAFEARRAY(unsigned char) *Data
);

Data [in]
A zero-based array of bytes that receives the response data received by Microsoft Windows HTTP Services (WinHTTP) up to the point that this event occurs. This is a VARIANT of type VT_ARRAY | VT_UI1.

来源:http://msdn.microsoft.com/en-us/library ... s.85).aspx

如何利用 OnResponseDataAvailable 编写 下载进度条 等等!!

比如:

Code: Select all

URLDownloadToFile(URL,FilePath,Timeout=-1)
  {
    ComObjError(0)  ;禁用 COM 错误通告。禁用后,检查 A_LastError 的值,脚本可以实现自己的错误处理
    WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
    WebRequest.Open("GET", URL, true)   ;true为异步获取,默认是false。龟速的根源!!!卡顿的根源!!!
    WebRequest.Send()
    WebRequest.WaitForResponse(Timeout) ;WaitForResponse 方法确保获取的是完整的响应
    ADO:=ComObjCreate("adodb.stream")   ;adodb.stream 才能读取 WebRequest.ResponseBody()
    ADO.Type:=1 ;以二进制方式操作
    ADO.Open()  ;开启物件
    ADO.Write(WebRequest.ResponseBody())    ;写入物件。注意没法将 WebRequest.ResponseBody() 存入一个变量,所以必须用这种方式写文件
    ADO.SaveToFile(FilePath,2)    ;文件存在则覆盖
    ADO.Close()
    return,1
  }

(通过它的事件函数,可以制作下载进度条!等)
garry
Posts: 1903
Joined: 22 Dec 2013, 12:50

Re: 有关 WinHttp.WinHttpRequest.5.1 事件函数!!

01 Apr 2014, 14:46

have no solution to this example
another example , downloadtofile with progressbar

Code: Select all

;- example downloads Autohotkey (ahk-install.exe)

;-------- saved at Donnerstag, 25. April 2013 18:59:42 user DataLife --------------
;-------- http://www.autohotkey.com/board/topic/17915-urldownloadtofile-progress/page-4 ---
surl:="http://www.auto-hotkey.com/download/ahk-install.exe"
;surl:="http://www.oocities.com/KindlyRat/GWBASIC.EXE.zip"

SplitPath, surl, name, dir, ext, name_no_ext, drive

sFile=%a_desktop%\%name%
ifexist,%sFile%
   filedelete,%sFile%

;-----------------------------------------------
a:=a_tickcount
Progress, % "M W" . A_ScreenWidth//2, 0, 0 of 0
VarSetCapacity(vt, 4*11), nParam = 31132253353
Loop, Parse, nParam
	NumPut(RegisterCallback("DownloadProgress", "Fast", A_LoopField, A_Index-1), vt, 4*(A_Index-1))
DllCall("urlmon\URLDownloadToFileA", "Uint", 0, "str", sUrl, "str", sFile, "Uint", 0, "UintP", &vt)
delta:=((a_tickcount-a)/1000)
msgbox, 262208,Downloaded ,Downloaded`n%name% to Desktop`n in %delta% seconds
exitapp
return

DownloadProgress(pthis, nProgress = 0, nProgressMax = 0, nStatusCode = 0, pStatusText = 0)
{
	If A_EventInfo = 6
	Progress, % p := 100 * nProgress//nProgressMax, %p%, % nProgress . " of " . nProgressMax
	Return 0
}
return
;----------------------------------

esc::exitapp
wzxiaodu
Posts: 12
Joined: 30 Nov 2013, 09:42

Re: 有关 WinHttp.WinHttpRequest.5.1 事件函数!!

01 Apr 2014, 23:30

QQ截图20140402122900.png
老大,一运行就出现上面那个内容,
文件却没下下来!
garry
Posts: 1903
Joined: 22 Dec 2013, 12:50

Re: 有关 WinHttp.WinHttpRequest.5.1 事件函数!!

02 Apr 2014, 13:42

for me worked, I use AHK_L ( older version 1.1.13.00 at the moment ) and also with AHK_Basic ( 1.0.48.05) , OS is windows XP

Return to “请求帮助”

Who is online

Users browsing this forum: No registered users and 12 guests