Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi IdHTTP Get Auth Problem (https://www.delphipraxis.net/42659-idhttp-get-auth-problem.html)

bate 22. Mär 2005 09:20


IdHTTP Get Auth Problem
 
Hallo,

hab ne IdHTTP Komponente auf meinem Form.
habe nun das Problem wenn ich Request.Username und Password setze wird keine Exception
geworfen von den Komponenten bei Fehlerhaftem Login/Passwort. Es kommt im Get der Text der Unten steht.
Jemand ne Idee? Ich möchte nicht unbedingt den result Text auswerten müssen.

Zitat:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>401 Authorization Required</TITLE>
</HEAD><BODY>
<H1>Authorization Required</H1>
This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.


<HR>
<ADDRESS>Apache/1.3.33 Server at _________ Port 80</ADDRESS>
</BODY></HTML>
Delphi-Quellcode:
procedure test();
var
  LClient : TIdHTTP;
begin
  LCLient := TIdHTTP.create(nil);
  try
    with LCLient do
    begin
      with Request do
      begin
        Username := 'falscherlogin';
        Password := 'falschespw';
        BasicAuthentication := true;
      end;

      try
        s := Get('http://www.meindomain.de/mitpasswort/index.html');
        MessageDlg('Test war erfolgreich: ' + s, mtInformation, [mbOK], 0);
      except
        on e : Exception do MessageDlg('Fehler: '+ e.Message, mtWarning, [mbOK],0);
      end;
    end;
  finally
    LCLient.Free;
  end;
end;
bei dem hier kommt per Get keine Exception. Sobald man aber das "with Request ..." auskommentiert
gibts wieder ne exception. :(
Ich würd aber gern testen wollen ob der login/pw richtig ist.

Basilikum 22. Mär 2005 10:45

Re: IdHTTP Get Auth Problem
 
du must nach Get() den ResponseCode überprüfen (LClient.ResponseCode)

200 = OK
401 = Unauthorized

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

bate 22. Mär 2005 10:59

Re: IdHTTP Get Auth Problem
 
Super genau das hab ich die ganze Zeit gesucht :)


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:03 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz