How to download from Delphi?

2

Hello, I created an application in Delphi , but it needs to download some files that I have on a website, but I have no idea how to do this, please help me. Ten of thanks for reading my question!

    
asked by anonymous 06.06.2015 / 20:10

1 answer

2

You can use URLDownloadToFile function :

// Inclua em "Uses" a unit "Urlmon"
function BaixarArquivo(const URL, SalvarComo: string): Boolean;
var
  H: HRESULT;
begin
  H := URLDownloadToFile(nil, pchar(URL),
                              pchar(SalvarComo),
                              0,
                              nil);
  Result := H = S_OK;
end;

Example usage:

if BaixarArquivo('http://www.fooBAR.com/baz.poo', 'C:\baz.poo') then
  ShowMessage('Arquivo baixado com sucesso!')
else
  ShowMessage('Falha ao baixar arquivo.');

There is also how to do this with the component TIdHTTP with method Get .

    
06.06.2015 / 20:36