title: Delphi download file from Web with Form authorization
body: <p>I need download file from Web with authorization.
  I use Delphi and Indy components.
  When the method Get performs the download, I get error "HTTP/1.0 404 Not Found".
  That seems to say that the authorization is failed, but file Response.html contains Web page, similar to the one that appears after login … </p>
  
  <p>P.S. Prams for authorization form I took using Firefox Web development tools.</p>
  
  <pre><code>function TForm1.Login: string;
  var
      Request: TStringList;
  begin
      Result := '';
      try
          Request := TStringList.Create;
          try
              Request.Add('backurl=%2Fnewupgrade%2Findex.php');
              Request.Add('AUTH_FORM=Y');
              Request.Add('TYPE=AUTH');
              Request.Add('USER_LOGIN=xxxx');
              Request.Add('USER_PASSWORD=XXXX');
              IdHTTP1.AllowCookies := True;
              IdHTTP1.HandleRedirects := True;
              IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
              IdHTTP1.Request.Connection := 'keep-alive';
              Result := IdHTTP1.Post('http://www.uniko.ru/newupgrade/index.php?login=yes', Request);
          finally
              Request.Free;
          end;
      except
          on E: Exception do ShowMessage(E.Message);
      end;
  end;
  
  procedure TForm1.Button1Click(Sender: TObject);
  var
      Response: string;
      fs: TStreamWriter;
      MS: TMemoryStream;
  begin
      Response := Login;
      fs := TStreamWriter.Create('C:\Response.html');
      fs.Write(Response);
      fs.Free;
  
      // Download file
      MS := TMemoryStream.Create;
      try
          IdHTTP1.Request.ContentType := 'application/force-download; name="Setup.EXE"';
          IdHTTP1.Get('http://www.uniko.ru/newupgrade/izyat/Setup.EXE', MS);
          MS.SaveToFile('C:\Setup.tmp');
      finally
          MS.Free;
      end
  end;
  </code></pre>
  
  <p></p>