使用Indy下载时,我应该怎么做"302 Found"例外?

opc*_*0de 5 delphi indy

我正在尝试将文件下载到字符串:

function FetchUrl(const url: string): string;
var
 idhttp : TIdHTTP;
begin
  idhttp := TIdHTTP.Create(nil);
  try
    Result := idhttp.Get(url);
  finally
    idhttp.Free;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

这段代码有什么问题?我得到一个例外:HTTP/1.1 302 Found

Rem*_*eau 10

TIdHTTP.HandleRedirects属性设置为True.默认情况下为False.

function FetchUrl(const url: string): string; 
var 
 idhttp : TIdHTTP; 
begin 
  idhttp := TIdHTTP.Create(nil); 
  try 
    idhttp.HandleRedirects := True;
    Result := idhttp.Get(url); 
  finally 
    idhttp.Free; 
  end; 
end; 
Run Code Online (Sandbox Code Playgroud)