url:="http://www.baidu.com";
sid:=Createhttpsession();
SetHttpAcceptencoding(sid,"gzip");//设定压缩格式编码类型
sethttpcallback(sid,findfunction("DownProg01")); //进度回调
r:=GetHttp(url,60000,v,code);
echo "\r\nDone",'->code:',code,'->返回内容总长度:',length(v),"\r\n";
return 0;
//--------------进度回调函数---------------------
function DownProg01(sid,AlldnB,dnB,AllupB,upB); //progresscallback-不提前结束
begin
if dnB > 0 then //如果大于0则打印
begin
echo "AlldnB:",AlldnB,",dnB:",dnB,",AllupB:",AllupB,",upB:",upB,"\r\n";
end;
return 0; //not done
end;
打印结果:
注:当http进度回调时,当服务器使用分块传输(启用压缩通常会使用分块传输)时, 无法预先知道总大小所以可能出现为0的情况,属于正常现象。