() '状态3表示开始接收数据,显示进度'
if http.readystate=4 then exit for '状态4表示数据接受完成'
wscript.sleep 500 '等待500ms'
next
if not http.readystate=4 then die("Timeout.") '1分钟还没下完20k?超时!'
if http.status>299 then die("Error: "&http.status&" "&http.statustext) '不是吧,又出错?'
if not http.status=206 then die("Server Not Support Partial Content.") '服务器不支持断点续传'
aso.type=1 '数据流类型设为字节'
aso.open
aso.loadfromfile filename '打开文件'
aso.position=start '设置文件指针初始位置'
aso.write http.responsebody '写入数据'
aso.savetofile filename,2 '覆盖保存'
aso.close
range=http.getresponseheader("Content-Range") '获得http头中的"Content-Range"'
if range="" then die("Can not get range.") '没有它就不知道下载完了没有'
temp=mid(range,instr(range,"-")+1) 'Content-Range是类似123-456/789的样子'
current=clng(left(temp,instr(temp,"/")-1)) '123是开始位置,456是结束位置'
total=clng(mid(temp,instr(temp,"/")+1)) '789是文件总字节数'
if total-current=1 then exit do '结束位置比总大小少1就表示传输完成了'
start=start+20480 '否则再下载20k'
loop while true
wscript.echo chr(13)&"Download ("&total&") Done." '下载完了,显示总字节数'
function die(msg) '函数名来自Perl内置函数die'
wscript.echo msg '交代遗言^_^'
wscript.quit '去见马克思了'
end function
function showplan() '显示下载进度'
if i mod 3 = 0 then c="/" '简单的
if http.readystate=4 then exit for '状态4表示数据接受完成'
wscript.sleep 500 '等待500ms'
next
if not http.readystate=4 then die("Timeout.") '1分钟还没下完20k?超时!'
if http.status>299 then die("Error: "&http.status&" "&http.statustext) '不是吧,又出错?'
if not http.status=206 then die("Server Not Support Partial Content.") '服务器不支持断点续传'
aso.type=1 '数据流类型设为字节'
aso.open
aso.loadfromfile filename '打开文件'
aso.position=start '设置文件指针初始位置'
aso.write http.responsebody '写入数据'
aso.savetofile filename,2 '覆盖保存'
aso.close
range=http.getresponseheader("Content-Range") '获得http头中的"Content-Range"'
if range="" then die("Can not get range.") '没有它就不知道下载完了没有'
temp=mid(range,instr(range,"-")+1) 'Content-Range是类似123-456/789的样子'
current=clng(left(temp,instr(temp,"/")-1)) '123是开始位置,456是结束位置'
total=clng(mid(temp,instr(temp,"/")+1)) '789是文件总字节数'
if total-current=1 then exit do '结束位置比总大小少1就表示传输完成了'
start=start+20480 '否则再下载20k'
loop while true
wscript.echo chr(13)&"Download ("&total&") Done." '下载完了,显示总字节数'
function die(msg) '函数名来自Perl内置函数die'
wscript.echo msg '交代遗言^_^'
wscript.quit '去见马克思了'
end function
function showplan() '显示下载进度'
if i mod 3 = 0 then c="/" '简单的
| 对此文章发表了评论 |

