Announcement

Collapse
No announcement yet.

Basic Authorization mit TIdHTTP

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Basic Authorization mit TIdHTTP

    Hallo,

    ich habe folgendes Problem:
    Ich möchte per TIdHTTP Daten an einen Server schicken. Die URL, die ich ansprechen muss ist dabei mit einer .HTACCESS geschützt (HTTP Basic Authorization) und ich versuche momentan bei dem Event OnAuthorization Username und Password zu setzen.
    Leider ohne Erfolg.
    Ich bekomme nur einen HTTP-401 Fehler zurück, aber keine erfolgreiche Anmeldung.
    Was mache ich falsch?

    Quellcode:
    [...]
    procedure TForm1.FormCreate(Sender: TObject);
    var liste: TStrings;
    begin
    IdHTTP1.Host := 'localhost';
    IdHTTP1.Port := 80;
    liste := TStringlist.Create;
    liste.Add('var1=wert1');
    liste.Add('var2=1234');
    IdHTTP1.Post('http://server/request.php', liste);
    Memo1.Lines.Add(IdHTTP1.ResponseText);
    end;

    procedure TForm1.IdHTTP1Authorization(Sender: TObject;
    Authentication: TIdAuthentication; var Handled: Boolean);
    begin
    Memo1.Lines.Add('Authentication...');
    Authentication.Username := 'max';
    Authentication.Password := 'mustermann';
    Handled := true;
    end;

    Vielen Dank für die Hilfe schonmal im Voraus.

    Grüße
    Robert Kummer

  • #2
    Wer ähnliches Problem hat, hier die Lösung:

    TIdHTTP.Request.BasicAuthentication := true;
    TIdHTTP.Request.Username := 'john';
    TIdHTTP.Request.Password := 'doe';

    Dann klappt's auch mit der Mutti...

    *blöde Standardeinstellungen*

    Grüße
    Robert Kummer

    PS.: Danke an Michael Knauer, der mir den Blick dafür schärfte. ;-

    Comment

    Working...
    X