Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi IdHTTP + Proxy + Anmeldung am Proxy mit eigenem Fenster (https://www.delphipraxis.net/94642-idhttp-proxy-anmeldung-am-proxy-mit-eigenem-fenster.html)

RWarnecke 24. Jun 2007 20:00


IdHTTP + Proxy + Anmeldung am Proxy mit eigenem Fenster
 
Hallo zusammen,

wenn ich den Usernamen und das Passwort direkt im Code einfüge funktioniert alles wunderbar. Nur wenn es über das eigene Fenster geht, bekomme ich immer wieder den Fehler 407, das eine Proxy Authentifizierung fehlt oder gebraucht wird. Hier mal mein Code :
Delphi-Quellcode:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP, IdAuthentication;

type
  TForm2 = class(TForm)
    IdHTTP1: TIdHTTP;
    Label1: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure IdHTTP1ProxyAuthorization(Sender: TObject;
      Authentication: TIdAuthentication; var Handled: Boolean);
  private
    procedure ConfigIdHTTP;
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

uses
  Unit3;

procedure TForm2.ConfigIdHTTP;
begin
  IdHTTP1.ProxyParams.ProxyServer := 'proxy.domain.de';
  IdHTTP1.ProxyParams.ProxyPort := 8080;
  Label1.Caption := IdHTTP1.Get('http://ip.smartcoder.net/txt/');
end;

procedure TForm2.IdHTTP1ProxyAuthorization(Sender: TObject;
  Authentication: TIdAuthentication; var Handled: Boolean);
begin
  if Form3.ShowModal = mrOK then
  begin
    IdHTTP1.ProxyParams.BasicAuthentication := true;
    IdHTTP1.ProxyParams.ProxyUsername := Form3.LabeledEdit1.Text;
    IdHTTP1.ProxyParams.ProxyPassword := Form3.LabeledEdit2.Text;
  end;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  ConfigIdHTTP;
end;

end.
Packe ich alles in die Procedure Button1Click, funktioniert es. Ich möchte aber nur dann die Form 3 sehen, wenn der Proxy eine Authentifizierung braucht. Wie mache ich das ?
[delphi]

RWarnecke 25. Jun 2007 20:42

Re: IdHTTP + Proxy + Anmeldung am Proxy mit eigenem Fenster
 
*push* Hat keiner eine Idee ???? *push*

RWarnecke 3. Jul 2007 16:35

Re: IdHTTP + Proxy + Anmeldung am Proxy mit eigenem Fenster
 
Hallo,

wenn ich die Prozedure OnProxyAuthentication so schreibe bekomme ich immer den Fehler, dass ich mich nicht authentifiziert habe :
Delphi-Quellcode:
procedure TForm4.IdHTTP1ProxyAuthorization(Sender: TObject;
  Authentication: TIdAuthentication; var Handled: Boolean);
begin
  if Form5.ShowModal = mrOK then
  begin
    Authentication.Username := Form5.LabeledEdit1.Text;
    Authentication.Password := Form5.LabeledEdit2.Text;
    Handled := true;
  end;
end;
Wie bekomme ich jetzt aus der Form5 den Usernamen und das Password an die IdHTTP übergeben ?

shmia 3. Jul 2007 17:47

Re: IdHTTP + Proxy + Anmeldung am Proxy mit eigenem Fenster
 
Du musst sicher vor dem 1. Get alle ProxyParameter (mit Ausnahme von User & Passwort) vorgeben:
Delphi-Quellcode:
IdHTTP1.ProxyParams.ProxyServer := 'proxy.domain.de';
IdHTTP1.ProxyParams.ProxyPort := 8080;
IdHTTP1.ProxyParams.BasicAuthentication := true;
Wird der Eventhandler für OnProxyAuthorization aufgerufen? Wenn ja, enthält das Objekt ProxyParams danach alle nötigen Werte?

RWarnecke 4. Jul 2007 07:34

Re: IdHTTP + Proxy + Anmeldung am Proxy mit eigenem Fenster
 
Zitat:

Zitat von shmia
Delphi-Quellcode:
IdHTTP1.ProxyParams.BasicAuthentication := true;

Diese Zeile habe ich eingefügt, aber trotzdem gibt es keine Authentifizierung.
Zitat:

Zitat von shmia
Wird der Eventhandler für OnProxyAuthorization aufgerufen? Wenn ja, enthält das Objekt ProxyParams danach alle nötigen Werte?

Die OnProxyAuthorization wird aufgerufen und die Werte aus den Editfeldern, wird auch an Authentication übergeben. Nur bin ich bis jetzt noch nicht dahinter gestiegen, wie ich dann die Werte an die ProxyParams über gebe. Ich dachte, dass das IdHTTP automatisch macht, was aber anscheinend nicht so ist.

RWarnecke 4. Jul 2007 08:39

Re: IdHTTP + Proxy + Anmeldung am Proxy mit eigenem Fenster
 
Hallo zusammen,

ich habe jetzt die Lösung gefunden :bounce1: :bouncing4: :dancer:

Ihr müsst den Wert hoInProcessAuth auf True setzen. Dann verwendet Ihr folgendes Beispiel :
Delphi-Quellcode:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP, IdAuthentication;

type
  TForm2 = class(TForm)
    IdHTTP1: TIdHTTP;
    Label1: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure IdHTTP1ProxyAuthorization(Sender: TObject;
      Authentication: TIdAuthentication; var Handled: Boolean);
  private
    procedure ConfigIdHTTP;
  public
    { Public-Deklarationen } 
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm} 

uses
  Unit3;

procedure TForm2.ConfigIdHTTP;
begin
  IdHTTP1.ProxyParams.ProxyServer := 'proxy.domain.de';
  IdHTTP1.ProxyParams.ProxyPort := 8080;
  IdHTTP1.ProxyParams.BasicAuthentication := true;
  Label1.Caption := IdHTTP1.Get('http://ip.smartcoder.net/txt/');
end;

procedure TForm2.IdHTTP1ProxyAuthorization(Sender: TObject;
  Authentication: TIdAuthentication; var Handled: Boolean);
begin
  if Form3.ShowModal = mrOK then
  begin
    Authentication.Username := Form3.LabeledEdit1.Text;
    Authentication.Password := Form3.LabeledEdit2.Text;
  end;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  ConfigIdHTTP;
end;

end.
Damit sollte die Proxyauthentifizierung funktionieren. So tut es zumindest bei mir. Über Feedback ob die Beispiel-Unit funktioniert wäre ich sehr dankbar, Würde dann auch nochmal einen Beitrag verfassen für die Code-Library.


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:33 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