回复 1# qinylj
不知道你是用的什么网络,这里测试没问题。
测试用的代码:
#include <WinHttp_GetRespond.au3>
$MyOpen=_WinHttpOpen()
Local $Request[3]=["$hRequest",@ScriptDir &"\暖色调悲伤01.flv",32] ;-----该参数与 _DownLoadByResPodn 的参数相对应
$rContext=_WinHTTP_GetRespond($MyOpen,"http://192.168.11.3/G%3A/暖色调悲伤01.flv",-1,-1,-1,-1,-1,-1,"_DownLoadByResPodn",$Request)
If Not @error Then
MsgBox(64,"Example 5 结果","下载完成!")
Else
MsgBox(48,@error,$rContext)
EndIf
_WinHttpCloseHandle($MyOpen)
Func _DownLoadByResPodn($hRequest,$SaveFile,$FileBlock)
$File=FileOpen($SaveFile,18)
Local $TotalLength =_WinHttpQueryHeaders($hRequest,$WINHTTP_QUERY_CONTENT_LENGTH) ;文件长度
Local $ri = 0, $TotalTime = TimerInit(), $StepTime = TimerInit(),$Stepri = 0
For $i = 1 To 1000000
$rDate= _WinHttpReadData($hRequest,2,1024 * $FileBlock)
If @error Then ExitLoop
FileWrite($File,$rDate)
$ri += BinaryLen($rDate)
$Stepri += BinaryLen($rDate)
If TimerDiff($StepTime) >= 998 Then
ConsoleWrite('At '& @HOUR & ':' & @MIN & ':' & @SEC & ' - 下载速度:' & $Stepri / 1024 &" KB" & ' 已完成:' & Round($ri / $TotalLength * 100,2) & '%' &@CRLF)
$StepTime = TimerInit()
$Stepri = 0
EndIf
Sleep(1)
Next
ConsoleWrite("Done .用时:" & Int(TimerDiff( $TotalTime )/1000) & ' Sec ,文件总大小:'& $TotalLength / 1024 & 'KB' &@CRLF)
FileClose($File)
_WinHttpCloseHandle($hRequest)
Return
EndFunc
|