Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I do about "302 Found" exceptions when downloading with Indy?

Tags:

delphi

indy

I am trying to download a file to a string:

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

What is wrong with this code? I get an exception: HTTP/1.1 302 Found

like image 395
opc0de Avatar asked Dec 20 '11 15:12

opc0de


1 Answers

Set the TIdHTTP.HandleRedirects property to True. It is False by default.

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; 
like image 92
Remy Lebeau Avatar answered Sep 28 '22 03:09

Remy Lebeau