Samuel
Samuel

Reputation: 55

Problems with authorization after upgrading from Delphi 2005 to 2010 using Indy http (idHTTP1.Get)

I'm upgrading from Delphi 2005 to Delphi 2010. I'm having this problem : the following procedure works well on D2005 but on D2010 I got always the result :

<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD>
<BODY><H1>401 Unauthorized</H1>
Your client does not have permission to get URL /axis-cgi/date.cgi from this server.
</BODY></HTML>

On the procedure, I try to connect twice because on D2005, sometimes I got an Unauthorized answer at my first try, and then I can connect at the second time with no problem. With D2010 I always get the Unauthorized answer.

The Url = 'http://user:[email protected]/axis-cgi/date.cgi?action=get'

function TViewCameraForm.HttpGet(idHTTP : TidHTTP; Url : AnsiString): AnsiString;
Var
  Res : AnsiString;
Begin
  idHTTP1.Disconnect;
  try
    Res := idHTTP1.Get(Url);
    If Pos('Unauthorized', Res) > 0 Then
        Res := idHTTP1.Get(Url);
    Result := Res;
  except
    on E: EIdHTTPProtocolException do begin
        Result := E.ErrorMessage
    end;
    on E: Exception do begin
        Result := E.message;
    end;
  end;

End;    

Thanks Sam

Upvotes: 3

Views: 1097

Answers (1)

mjn
mjn

Reputation: 36634

Did you try to authenticate using Basic Auth?

  ...
  idHTTP1.Request.BasicAuthentication := True;
  idHTTP1.Request.Username := 'user';
  idHTTP1.Request.Password := 'pass';
  Res := idHTTP1.Get(Url);

(using user:pass@website does not conform to the HTTP specification btw)

Upvotes: 7

Related Questions