在下载之前,使用delphi以编程方式从远程文件中获取文件大小

在下载之前,使用delphi以编程方式从远程文件中获取文件大小

问题描述:

在使用Delphi下载之前,如何确定网络上托管的远程文件的大小(以字节为单位)?

How i can determine the size in bytes of a remote file hosted in the web, before download it, using Delphi?

预先感谢。

您可以使用Indy。

首先包含 IdHTTP

您可以通过以下方式获取大小:

You can retrieve the size this way:

procedure TFormMain.Button1Click(Sender: TObject);
var
  Http: TIdHTTP;
begin
  Http := TIdHTTP.Create(nil);
  try
    Http.Head('http://live.sysinternals.com/ADExplorer.exe');

    ShowMessage(IntToStr(Http.Response.ContentLength));
  finally
    Http.Free;
  end;
end;