RSS订阅 | 匿名投稿
您的位置:网站首页 > 网络 > 正文

DELPHI IDHTTP下载带清理网络缓存

作者:admin 来源: 日期:2015/4/27 20:21:58 人气: 标签:

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;

读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址:
下一篇:没有资料