Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.12.05;
Скачать: CL | DM;

Вниз

Как можно скачать файл при помощи IdHTTP ?   Найти похожие ветки 

 
Наташа   (2004-09-29 15:38) [0]

Как можно скачать файл при помощи IdHTTP ?


 
fuzzy ©   (2004-09-29 17:40) [1]

Вообще, можно и без него файлы качать, универсально для D4-D7


uses
 URLMon, ShellApi;

function DownloadFile(SourceFile, DestFile: string): Boolean;
begin
 try
   Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;
 except
   Result := False;
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
const
 // URL Location
 SourceFile = "http://www.google.com/intl/de/images/home_title.gif";
 // Where to save the file
 DestFile = "c:\temp\google-image.gif";
begin
 if DownloadFile(SourceFile, DestFile) then
 begin
   ShowMessage("Download succesful!");
   // Show downloaded image in your browser
   ShellExecute(Application.Handle, PChar("open"), PChar(DestFile),
     PChar(""), nil, SW_NORMAL)
 end
 else
   ShowMessage("Error while downloading " + SourceFile)
end;

// Minimum availability: Internet Explorer 3.0
// Minimum operating systems Windows NT 4.0, Windows 95

{********************************************************}

{2.способ}

uses
 Wininet;

function DownloadURL(const aUrl: string): Boolean;
var
 hSession: HINTERNET;
 hService: HINTERNET;
 lpBuffer: array[0..1024 + 1] of Char;
 dwBytesRead: DWORD;
begin
 Result := False;
 // hSession := InternetOpen( "MyApp", INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);
 hSession := InternetOpen("MyApp", INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
 try
   if Assigned(hSession) then
   begin
     hService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, 0, 0);
     if Assigned(hService) then
       try
         while True do
         begin
           dwBytesRead := 1024;
           InternetReadFile(hService, @lpBuffer, 1024, dwBytesRead);
           if dwBytesRead = 0 then break;
           lpBuffer[dwBytesRead] := #0;
           Form1.Memo1.Lines.Add(lpBuffer);
         end;
         Result := True;
       finally
         InternetCloseHandle(hService);
       end;
   end;
 finally
   InternetCloseHandle(hSession);
 end;
end;


 
Наташа   (2004-09-30 17:36) [2]

Благодарю!!!



Страницы: 1 вся ветка

Текущий архив: 2004.12.05;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.052 c
14-1100756936
gn
2004-11-18 08:48
2004.12.05
Билл Гейтс: пароль мертв


3-1099685535
Hmm
2004-11-05 23:12
2004.12.05
связь таблиц. "combobox в dbgride"


3-1099564954
Sour
2004-11-04 13:42
2004.12.05
Блокировка сущностей в БД


3-1099552873
Sergeich
2004-11-04 10:21
2004.12.05
Центр и филиал


3-1099659796
alsov1
2004-11-05 16:03
2004.12.05
Как передать в TQuery параметр равный null