Indy (Delphi) Http Client and Digest Authentication

I am trying to connect to a local network server (http: //) that needs digest authentication.

uses IdHttp, IdAuthenticationDigest;

...

begin
  IdHttp1 := TIdHttp.Create(nil);
  try
    IdHttp1.Request.Username := 'xxx';
    IdHttp1.Request.Password := 'xxx';

    Result := IdHttp1.Get(URL)
  finally
    idHttp1.Free;
  end;
end; 

      

Unfortunately I am getting HTTP / 1.0 401 Unauthorized as IdHttp1.ResponseText from the server. Both Firefox and Chrome connect fine if I enter my username and password.

I have the latest Indy 10 from SVN and Delphi 7.

Server HTTP header (192.168.1.10 over LAN):

Connecting...
Resolving hostname dm7020hd.
Connecting to 192.168.1.10.
Connected.
Server: webserver/1.0
Date: Thu, 31 Jan 2013 11:28:32 GMT
WWW-Authenticate: Digest algorithm="MD5", realm="Forbidden", qop="auth", opaque="7edfc2c756ad1f795651f15f88c32b25", nonce="d2ef913b753b3b6ad8878b34b93cfc5a"
Content-Type: text/html
Cache-Control: no-store, no-cache, must-revalidate
Expires: Sat, 10 Jan 2000 05:00:00 GMT
Content-Length: 15
Last-Modified: Thu, 31 Jan 2013 11:28:32 GMT
ETag: "753868328"
Connection: close
Disconnected

      

I have a lot of experience with this issue and from the looks of it a lot of people have problems with indy authentication (does this work at all?).

+3


source to share


1 answer


You need to include a flag hoInProcessAuth

on the property TIdHTTP.HTTPOptions

. It is disabled by default. Without this flag, TIdHTTP.Get()

it won't send a second HTTP request specifying the digest credentials in response to the 401 response from the server. It just exits and expects you to process the 401 response and send a new request yourself as needed.



+5


source







All Articles