var
Http: TNetHTTPClient;
httpRequest: TNetHTTPRequest;
begin
HttpClient:=TNetHTTPClient.create(
nil);
HttpClient.OnAuthEvent:=NetHTTPClientAuthEvent;
HttpClient.OnReceiveData:=NetHTTPClientReceiveData;
HttpClient.OnRequestError:=NetHTTPClientRequestError;
HttpClient.ConnectionTimeout:=180.000;
//3 min
HttpClient.ResponseTimeout:=1800000;
//30 min
for i:=0
to list.count - 1
do
begin
httpRequest:=TNetHTTPRequest.create(
nil);
try
httpRequest.Client:=HttpClient;
httpRequest.Asynchronous:=False;
HttpRequest.ConnectionTimeout:=180000;
//3 min
HttpRequest.ResponseTimeout:=1800000;
//30 min
ms:=TFileStream.create(list[i].localFilename + '
.tmp', fmCreate
or fmOpenReadWrite);
try
try
httpRequestHasError:=false;
httpRequest.get(StringReplace(StringReplace(StringReplace(list[i].remoteFilename, '
', '
%20', [rfReplaceAll]),
'
´', '
%C2%B4', [rfReplaceAll]),
'
`', '
%60', [rfReplaceAll]), ms);
if (httpRequestHasError)
then
raise Exception.Create(httpRequestHasErrorText);
except
on E: System.SysUtils.Exception
do
begin
//retry
end;
end;
finally
ms.Free;
end;
finally
httpRequest.Free();
end;
end;
Http.Free();
end;
procedure NetHTTPClientRequestError(
const Sender: TObject;
const AError:
String);
begin
mlog.info('
Error during download: ' + AError);
httpRequestHasErrorText:='
Error during download: ' + AError;
httpRequestHasError:=true;
end;
procedure NetHTTPClientAuthEvent(
const Sender: TObject; AnAuthTarget: TAuthTargetType;
const ARealm, AURL:
string;
var AUserName, APassword:
string;
var AbortAuth: Boolean;
var Persistence: TAuthPersistenceType);
begin
AUserName:='
xxx';
APassword:='
yyy';
end;
procedure TicTrainerF.NetHTTPClientReceiveData(
const Sender: TObject; AContentLength, AReadCount: Int64;
var Abort: Boolean);
begin
end;