Einzelnen Beitrag anzeigen

MartinK

Registriert seit: 21. Jun 2009
Ort: Germering (Germany)
89 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#16

AW: Proxy-Einstellungen automatisch erkennen mit IDHttp

  Alt 2. Mai 2013, 15:38
Ich habe mich heute nochmal an das Thema gemacht.

Good news: inzwischen funktioniert IDHTTP bei mir auf einem NTML authentifiziertem Proxy-Server!
Der Code sollte ebenso "Digest" und "Basic" Proxy Authentifizierung beherrschen, was ich aber in Ermangelung eines entsprechenden Proxies noch nicht austesten konnte.

Was ist zu tun:
- Ein IDHTTP Element auf das Form legen
- Ein IdSSLIOHandlerSocketOpenSSL auf das Form legen
- Beim IDHTTP Element im IOHandler "IdSSLIOHandlerSocketOpenSSL" auswählen

- Folgende evtl. noch fehlenden Anweisungen in die Uses Klausel aufnehmen:
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdAuthenticationSSPI , IdAuthentication , IdAuthenticationDigest , IdHeaderList, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL ;

- URL und Port des Proxies irgendwo übergeben (uB in FormCreate)

Delphi-Quellcode:
           IdHTTP1.ProxyParams.ProxyServer := 'MyProxyServer';
           IdHTTP1.ProxyParams.ProxyPort := 'MyProxyPort';


- Folgendes in IdHTTPMainSelectProxyAuthorization aufnehmen

Delphi-Quellcode:
procedure TForm1.IdHTTPMainSelectProxyAuthorization(Sender: TObject; var AuthenticationClass: TIdAuthenticationClass; AuthInfo: TIdHeaderList);
begin
  // First check for NTLM authentication, as you do not need to set username and password because Indy will automatically
  // handle passing your Windows Domain username and password to the proxy server
  if (pos('Proxy-Authenticate: NTLM', IdHTTPMain.Response.RawHeaders.Text)>0)
    then begin
           IdHTTP1.ProxyParams.BasicAuthentication := false;
           AuthenticationClass := TIdSSPINTLMAuthentication;
         end
    else begin
           //Next check for Basic
           if (pos('Proxy-Authenticate: Basic', IdHTTP1.Response.RawHeaders.Text)>0)
             then begin
                    AuthenticationClass := TIdBasicAuthentication;
                    IdHTTP1.ProxyParams.BasicAuthentication := true;
                   end
             else begin
                    // Then Digest
                    if (pos('Proxy-Authenticate: Digest', IdHTTPMain.Response.RawHeaders.Text)>0)
                      then AuthenticationClass := TIdDigestAuthentication
                  end;
           //.------------
           IdHTTP1.ProxyParams.ProxyUsername := 'YourUsername';
           IdHTTP1.ProxyParams.ProxyPassword := 'YourPassword';
         end;

end;

- Get-Funktion aufrufen um etwas zu machen. Z.B.

  Memo1.Lines.Text := IdHTTP1.Get('http://www.google.de'); Viel Spaß
Martin
Martin Kuhn

Geändert von MartinK ( 2. Mai 2013 um 15:43 Uhr)
  Mit Zitat antworten Zitat