delphi IDHTTP下载带清理网络缓存  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi IDHTTP下载带清理网络缓存


type
  THttpThread = class(TThread)
  private
    FIdHTTP: TIdHTTP;
    FUrl: string;
    FSavePath: string;
    procedure Down(Url: string; SavePath: string);
  public
    constructor Create(CreateSuspended: Boolean; Url: string; SavePath: string);
    destructor Destroy; override;
    procedure Execute; override;
  end;


{ THttpThread }

constructor THttpThread.create(CreateSuspended: Boolean; Url: string; SavePath: string);
begin
  inherited Create(CreateSuspended);
  FreeOnTerminate := True;
  FUrl := Url;
  FSavePath := SavePath;
  FIdHTTP := TIdHTTP.Create(nil);
end;

destructor THttpThread.Destroy;
begin
  FIdHTTP .Free;
  inherited;
end;

procedure THttpThread.Down(Url: string; SavePath: string);
var
  Stream: TMemoryStream;
begin
  BegTime := GetTickCount;
  Stream := TMemoryStream.Create;
  try
    try
      FIdHTTP.Get(Url, Stream);
    finally
      DeleteUrlCacheEntry(PChar(Url));
    end;
  except
    MessageBox(0, '网络出错', '提示', MB_ICONQUESTION);
    Stream.Free;
    Exit;
  end;

  Stream.SaveToFile(SavePath);
  Stream.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  HttpThread1: THttpThread;
  UrlPath: string;
begin
  UrlPath := 'http://www.3464.com/Images/TopLogo.gif';
  HttpThread1 := THttpThread.Create(False, UrlPath, 'C:\Test\1.Rar');
end;

procedure THttpThread.Execute;
begin
  inherited;
  Down(FUrl, FSavePath);
end;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.042257070541382 seconds