Einzelnen Beitrag anzeigen

MartinK

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

AW: Daten abholen von einem CakePHP Server

  Alt 29. Okt 2014, 15:27
Nachdem jetzt mit direktem www Zugang alles klappt, habe ich noch ein Thema sobald ich via Proxy verbinde

hier mal ein Stück Code das bei mir heraussucht welche Art von Proxy-Auth gemacht wird
Delphi-Quellcode:
procedure TForm1.IdHTTPProxyAuthorization(Sender: TObject; Authentication: TIdAuthentication; var Handled: Boolean);
begin
  Handled := False;
end;

function TForm1.IdSSLIOHandlerSocketOpenSSLVerifyPeer(Certificate: TIdX509; AOk: Boolean; ADepth, AError: Integer): Boolean;
begin
  Result := True;
end;


procedure TForm1.IdHTTPSelectProxyAuthorization(Sender: TObject; var AuthenticationClass: TIdAuthenticationClass; AuthInfo: TIdHeaderList);

begin
  ProxyAuthTxt := 'Proxy-Authentification: Unkown';

  // 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', IdHTTP.Response.RawHeaders.Text)>0)
    then begin
           IdHTTP.ProxyParams.BasicAuthentication := false;
           AuthenticationClass := TIdSSPINTLMAuthentication;
           ProxyAuthTxt := 'Proxy-Authentific.: NTML (w/o Username+PW)';
           ProxyAuthType := 1;
         end
    else begin
           //...now check for Basic Authentication
           if (pos('Proxy-Authenticate: Basic', IdHTTP.Response.RawHeaders.Text)>0)
             then begin
                    IdHTTP.ProxyParams.BasicAuthentication := true;
                    AuthenticationClass := TIdBasicAuthentication;
                    ProxyAuthTxt := 'Proxy-Authentification: Basic';
                    ProxyAuthType := 2;
                   end
             else begin
                    // Then Digest
                    if (pos('Proxy-Authenticate: Digest', IdHTTP.Response.RawHeaders.Text)>0)
                      then begin
                             IdHTTP.ProxyParams.BasicAuthentication := true;
                             AuthenticationClass := TIdDigestAuthentication;
                             ProxyAuthTxt := 'Proxy-Authentification: Digest';
                             ProxyAuthType := 3;
                           end;
                  end;
           //.------------
           IdHTTP.ProxyParams.ProxyUsername := EProxyUsername.Text;
           IdHTTP.ProxyParams.ProxyPassword := EProxyPassword.Text;
         end;

  LProxyAutent.Caption := ProxyAuthTxt;
end;

HTTP Get funktioniert auch einwandfrei solange ich ein normales get/Post mache,
"OHNE dem Server ein Username/Password für den Cloud-Zugriff mitzuübergeben"
(URL, Port und Pasword/Username wegen das proxys sind natürlcih angegeben passen !)


sobald ich den Cloud Username und Passwort mit angebe, bekomme ich beim "IdHttp.Get" eine Exception "HTTP/1.1 400 bad request"
Gehe ich ich aber nicht über den Proxy, sondern verbinde direkt, dann funktioniert der Code eiwandfrei;

Delphi-Quellcode:
Function TForm1.Ask4aCloudResponse(aUsername, aPassword, aServerURL, aServerCommand: String ):String;
begin
  try
    IdHTTP.HandleRedirects := True;

    iDHTTP.Request.BasicAuthentication := True;
    iDHTTP.Request.Authentication := TIdBasicAuthentication.Create;
    iDHTTP.Request.Authentication.Username := aUsername;
    iDHTTP.Request.Authentication.Password := aPassword;
    IdHTTP.Request.ContentType := 'application/json';
    Result := IdHttp.Get(aServerURL + aServerCommand);
  finally
    ;
  end;
end;
woran kann denn das liegen?
Martin Kuhn
  Mit Zitat antworten Zitat