Pobierz Plik z programu internet z wydarzeniem Progress za pomocą Delphi i Indy
Potrzebuję sposobu na pobranie pliku z Internetu za pomocą Delphi poprzez HTTP, Jeśli chodzi o Zdarzenie Progress, Szukam metody, która wykorzystuje komponenty Indy.
Używam Delphi 7.
Z góry dzięki.
14
1 answers
Zakodowałem ten przykład, używając tylko jednego HTTP GET, z Indy 10, mam nadzieję, że działa również z Indy 9:
uses
{...} IdHTTP, IdComponent;
type
TFormMain = class(TForm)
{...}
private
{...}
procedure HttpWork(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Int64);
end;
{...}
procedure TFormMain.Button1Click(Sender: TObject);
var
Http: TIdHTTP;
MS: TMemoryStream;
begin
Http := TIdHTTP.Create(nil);
try
MS := TMemoryStream.Create;
try
Http.OnWork:= HttpWork;
Http.Get('http://live.sysinternals.com/ADExplorer.exe', MS);
MS.SaveToFile('C:\ADExplorer.exe');
finally
MS.Free;
end;
finally
Http.Free;
end;
end;
procedure TFormMain.HttpWork(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Int64);
var
Http: TIdHTTP;
ContentLength: Int64;
Percent: Integer;
begin
Http := TIdHTTP(ASender);
ContentLength := Http.Response.ContentLength;
if (Pos('chunked', LowerCase(Http.Response.TransferEncoding)) = 0) and
(ContentLength > 0) then
begin
Percent := 100*AWorkCount div ContentLength;
MemoOutput.Lines.Add(IntToStr(Percent));
end;
end;
20
Author: ulrichb,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-02-04 14:07:58
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-02-04 14:07:58