Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido) download http


AllNet

Pergunta

2 respostass a esta questão

Posts Recomendados

  • 0

Alguns exemplos:

uses ExtActns, ...

type
   TfrMain = class(TForm)
   ...
   private
     procedure URL_OnDownloadProgress
        (Sender: TDownLoadURL;
         Progress, ProgressMax: Cardinal;
         StatusCode: TURLDownloadStatus;
         StatusText: String; var Cancel: Boolean);
   ...

implementation
...

procedure TfrMain.URL_OnDownloadProgress;
begin
   ProgressBar1.Max:= ProgressMax;
   ProgressBar1.Position:= Progress;
end;

function DoDownload;
begin
   with TDownloadURL.Create(self) do
   try
     URL:='http://z.about.com/6/g/delphi/b/index.xml';
     FileName := 'c:\ADPHealines.xml';
     OnDownloadProgress := URL_OnDownloadProgress;

     ExecuteTarget(nil);
   finally
     Free;
   end;
end;

{
Note:
URL property points to Internet
FileName is the local file
}
Outro exemplo:
uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls,
    CHILKATHTTPLib_TLB,
    OleCtrls;

...

procedure TForm1.Button1Click(Sender: TObject);
var
http: TChilkatHttp;
success: Integer;

begin
http := TChilkatHttp.Create(Self);

//  Any string unlocks the component for the 1st 30-days.
success := http.UnlockComponent('Anything for 30-day trial');
if (success <> 1) then
  begin
    ShowMessage(http.LastErrorText);
    Exit;
  end;

//  Download the Python language install.
//  Note: This URL may have changed since this example was created.
success := http.Download('http://www.python.org/ftp/python/2.5/python-2.5.msi','python-2.5.msi');
if (success <> 1) then
  begin
    ShowMessage(http.LastErrorText);
  end
else
  begin
    ShowMessage('Python Download Complete!');
  end;
end;
outro exemplo:
Download Internet File
uses WinInet; 
function GetInetFile (const fileURL, FileName: String): boolean;
const
  BufferSize = 1024;
var
  hSession, hURL: HInternet;
  Buffer: array[1..BufferSize] of Byte;
  BufferLen: DWORD;
  f: File;
  sAppName: string;
begin
 result := false;
 sAppName := ExtractFileName(Application.ExeName);
 hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
 try
  hURL := InternetOpenURL(hSession, PChar(fileURL), nil, 0, 0, 0);
  try
   AssignFile(f, FileName);
   Rewrite(f,1);
   repeat
    InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
    BlockWrite(f, Buffer, BufferLen)
   until BufferLen = 0;
   CloseFile(f);
   result := True;
  finally
   InternetCloseHandle(hURL)
  end
 finally
  InternetCloseHandle(hSession)
 end
end; 

Para usar a função

procedure TForm1.FormCreate(Sender: TObject);
begin
var
  internetFile,
  localFileName: string;
begin
 internetFile := 'http://z.about.com/6/g/delphi/b/index.xml';
 localFileName := 'About Delphi Programming RSS Feed.xml';

 if GetInetFile(internetFile, localFileName) then
   ShowMessage('Download successful.')
 else
   ShowMessage('Error in file download.');

end;
outro exemplo:
function DownloadFile(Source, Dest: string): Boolean;
begin
  try
    Result:= UrlDownloadToFile(nil, PChar(source),PChar(Dest), 0, nil) = 0;
  except
    Result:= False;
  end;
end;

Para usar esta function é preciso declarar Urlmon na seção uses da unit. Depois basta fazer uma chamada padrão:

procedure TForm1.FormCreate(Sender: TObject);
begin
   if DownloadFile ('http://www.onde.com/arq.htm','c:\arq.htm') then
     ShowMessage('Download Concluído.');
end;
outro exemplo:
uses ExtActns, ...

type
  TfrMain = class(TForm)
    ...
    private
    procedure URL_OnDownloadProgress(Sender: TDownLoadURL;
      Progress, ProgressMax: Cardinal;
      StatusCode: TURLDownloadStatus;
      StatusText: string; var Cancel: Boolean);
    ...
  implementation
    ...

procedure TfrMain.URL_OnDownloadProgress;
begin
  ProgressBar1.Max := ProgressMax;
  ProgressBar1.Position := Progress;
end;

function DoDownload;
begin
  with TDownloadURL.Create(self) do
  try
    URL := 'http://sua url.com.br';
    FileName := 'local e o nome que quer salvar';
    OnDownloadProgress := URL_OnDownloadProgress;
    ExecuteTarget(nil);
  finally
    Free;
  end;
end;
outro exemplo:
procedure TForm1.Button1Click(Sender: TObject);
var
 savedlg: TSaveDialog;
begin
savedlg := TSaveDialog.Create(Self);

if savedlg.Execute then
 if DownloadFile(Edit1.Text, savedlg.FileName) then
   MessageBox(Application.Handle, 'Download efetuado com sucesso', 'Informação', MB_ICONINFORMATION)
 else
   MessageBox(Application.Handle, 'Download falhou', 'Informação', MB_ICONEXCLAMATION);
end;


function TForm1.DownloadFile(Source, Dest: string): Boolean;
begin
try
  Result := UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0;
except
  Result := False;
end;

end;
outro exemplo:
Use o componente NMHTTP da palheta de Internet do Delphi.
Coloque o nome com o qual ele vai ser gravado na propriedade Body, Coloque

InputFileMode := True, e use
NMHTTP1.Get(’http://sitedesejato/pasta/arquivo.extensao’);
outro exempo:
Use o componente TIdHttp: 


procedure TForm1.Button1Click(Sender: TObject); 
var 
  vArquivo: TFileStream; 
begin 
  vArquivo := TFileStream.Create('c:\arquivo.txt',fmCreate); 
  Try 
     Try 
       idHTTP1.Get('http://www.site.com.br/arquivo.txt',vArquivo); 
     Except 
       ShowMessage('Não foi possivel baixar o arquivo !'); 
     End; 
  Finally 
     FreeAndNil(vArquivo); 
  End; 
end;

Outros

http://singularsistemas.com.br/blog/2008/0...tp-com-synapse/

abraço

Link para o comentário
Compartilhar em outros sites

  • 0

uses ExtActns, ...

type
   TfrMain = class(TForm)
   ...
   private
     procedure URL_OnDownloadProgress
        (Sender: TDownLoadURL;
         Progress, ProgressMax: Cardinal;
         StatusCode: TURLDownloadStatus;
         StatusText: String; var Cancel: Boolean);
   ...

implementation
...

procedure TfrMain.URL_OnDownloadProgress;
begin
   ProgressBar1.Max:= ProgressMax;
   ProgressBar1.Position:= Progress;
end;

function DoDownload;
begin
   with TDownloadURL.Create(self) do
   try
     URL:='http://z.about.com/6/g/delphi/b/index.xml';
     FileName := 'c:\ADPHealines.xml';
     OnDownloadProgress := URL_OnDownloadProgress;

     ExecuteTarget(nil);
   finally
     Free;
   end;
end;

{
Note:
URL property points to Internet
FileName is the local file
}

Obrigado Jhonas.

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...