Stoyan Toskov
Stoyan Toskov

Reputation: 29

Indy IdHttp Digest Authentication - 401

When you try to take a picture from a camera, the authentication function does not work. I read all the other posts on the subject, but without success with this device.

Indy 10.6.2.0

Uses ..., IdAuthentication, IdAuthenticationDigest;

...

  addr   := 'cgi-bin/snapshot.cgi?1';
  myADR :=  'http://87.126.245.25:8181/' + addr;

  rStream := TMemoryStream.Create;
  try

    H1 := TIdHttp.Create();

    {$IFDEF DEBUG}
    idLogFile := TIdLogFile.Create( H1 );
    with idLogFile do begin
      Filename := IncludeTrailingPathDelimiter( ExtractFileDir( Application.ExeName ) ) + 'indy_log.txt';
      Active := true;
    end;
    {$ENDIF}

    with H1 do begin

      Response.KeepAlive          := true;
      ReadTimeout                 := selCAM.Timeout;
      Request.BasicAuthentication := false;
      Request.Username            := selCAM.User;
      Request.Password            := selCAM.Pass;
      Request.ContentType         := 'image/jpeg';
      Request.UserAgent           := 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/97.0.4692.71';
      Request.ContentVersion      := '1.0';
      Request.IPVersion           := Id_IPv4;
      Request.Host                := 'http://' + addr;

      HTTPOptions := [hoInProcessAuth, hoForceEncodeParams];
    
      OnSelectAuthorization := IdHTTP_SelectAuthorization;
      OnHeadersAvailable    := IdHTTP_HeadersAvailable;
      OnAuthorization       := IdHTTP_Authorization;

      {$IFDEF DEBUG}  Intercept := idLogFile; {$ENDIF}
    end;

    try
    
      H1.Get( myADR, rStream); except

      on E: EIdHTTPProtocolException do begin SB1.Panels[0].Text := E.Message; er := true; end;
      on E: EIdException             do begin SB1.Panels[0].Text := E.Message; er := true; end;
      on E: Exception                do begin SB1.Panels[0].Text := E.Message; er := true; end;

    end;

  finally
    H1.Free;
    FreeAndNil(rStream);
  end;

It works correctly through a browser

Attach wireshark from Browser, from Indy and Indy Log:

https://1drv.ms/u/s!AubiEh1vqvRLkr01GzXCf_T0yLgmfQ?e=69dqaD

Upvotes: 0

Views: 595

Answers (0)

Related Questions