Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How open a url with http authentication in Delphi?

How open a url (a browser window) that need "http authentication" passing login and password in a transparent way? The legacy app in delphi need open a report in ".aspx" from Reporting Services.

Thanks, Celso

like image 945
celsowm Avatar asked Dec 28 '22 13:12

celsowm


2 Answers

Use the Indy TidHTTP component as it can easily handle the authentication requirements. Drop the component on the form and:

IdHTTP1.Request.UserName := 'xxx';
IdHTTP1.Request.Password := 'xxx';
IdHTTP1.Get(x);

I believe that works for whatever Indy version that you might have.

like image 75
Darian Miller Avatar answered Jan 02 '23 23:01

Darian Miller


You can use WinHTTP, check the IWinHttpRequest.SetCredentials method

check this sample

uses
  Variants,
  SysUtils,
  WinHttp_TLB;


Const
  HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0;
Var
  Http: IWinHttpRequest;
begin
  try
   Http := CoWinHttpRequest.Create;
   try
     Http.Open('GET', 'http://Foo.com/home', False);
     Http.SetCredentials('AUser','APassword', HTTPREQUEST_SETCREDENTIALS_FOR_SERVER);
     Http.Send(EmptyParam);

     //Do your stuff

   finally
     Http:=nil;
   end;
  except
    on E:Exception do
      Writeln(E.Classname, ': ', E.Message);
  end;
end.
like image 25
RRUZ Avatar answered Jan 03 '23 01:01

RRUZ