How to do NTLM Authentication using Indy 10 in Delphi 7? -


i want ntlm authentication indy 10 components in delphi 7 . here source code :

 uses   windows, messages, sysutils, variants, classes, graphics, controls, forms,   dialogs ,stdctrls, idbasecomponent, idcomponent, idtcpconnection,   idtcpclient, idhttp,idauthenticationsspi , idauthentication , idauthenticationdigest , idheaderlist;  procedure tform1.button1click(sender: tobject); begin    memo1.lines.add(   idhttp1.get('http://www.google.co.in')); end;  procedure tform1.idhttp1proxyauthorization(sender: tobject;       authentication: tidauthentication; var handled: boolean); var    username: string;    usernamelen: dword; begin    authentication.username := 'xxxxx';    authentication.password := 'xxxx';    handled := false;  // tried setting true , no changes in error end;    procedure tform1.idhttp1selectproxyauthorization(sender: tobject;      var authenticationclass: tidauthenticationclass;     authinfo: tidheaderlist);  begin    // first check ntlm authentication, not need   // set username , password because indy automatically      // handle passing windows domain username ,   // password proxy server   if (pos('proxy-authenticate: ntlm', idhttp1.response.rawheaders.text)>0)   begin     idhttp1.proxyparams.clear;     idhttp1.proxyparams.basicauthentication := false;    // set authentication class ntlm     //idhttp1.auth      authenticationclass := tidsspintlmauthentication;   end   else   begin     // next check basic     if (pos('proxy-authenticate: basic', idhttp1.response.rawheaders.text)>0)     begin       authenticationclass := tidbasicauthentication;       idhttp1.proxyparams.basicauthentication := true;    end    else    begin       // digest       if (pos('proxy-authenticate: digest', idhttp1.response.rawheaders.text)>0)          authenticationclass := tiddigestauthentication    end;    end;    idhttp1.proxyparams.proxyusername := 'xxxx';    idhttp1.proxyparams.proxypassword := 'xxxx';   end; 

as per read on internet, modified source code of idhttp.pas following :-

 function tidcustomhttp.doonproxyauthorization(arequest: tidhttprequest; aresponse: tidhttpresponse):      boolean; var    i: integer;    s: string;    auth: tidauthenticationclass; begin    inc(fauthproxyretries);    if not assigned(proxyparams.authentication)    begin      // find authentication method supported us.       := 0;      while < aresponse.proxyauthenticate.count      begin         s := aresponse.proxyauthenticate[i];      try         auth := findauthclass(fetch(s));         break;      except      end;      inc(i);    end;     if = aresponse.proxyauthenticate.count    begin       result := false;      exit;    end;     if assigned(fonselectproxyauthorization)    begin       onselectproxyauthorization(self, auth, aresponse.proxyauthenticate);    end;     {    proxyparams.authentication := auth.create;    end;     result := assigned(onproxyauthorization);    // clear password , reset autorization if previous failed    if (aresponse.fresponsecode = 407) begin        proxyparams.proxypassword := '';        proxyparams.authentication.reset;     end; }     /// *** changes start **** ////     if assigned(auth)    begin       proxyparams.authentication := auth.create;     end;   end;    result := assigned(proxyparams.authentication)  ,  assigned(onproxyauthorization);    // clear password , reset autorization if previous failed   if ((aresponse.fresponsecode = 407) ,       (not (proxyparams.authentication tidsspintlmauthentication)))   begin      proxyparams.proxypassword := '';      if assigned(proxyparams.authentication)      begin        proxyparams.authentication.reset;      end;   end;    //// **** changes end *** /////   if result   begin    proxyparams.authentication    begin      username := proxyparams.proxyusername;      password := proxyparams.proxypassword;      authparams := aresponse.proxyauthenticate;   end;  result := false;  repeat   case proxyparams.authentication.next of     wnasktheprogram: // ask user porgram supply authorization information       begin         if assigned(onproxyauthorization)         begin           proxyparams.authentication.username := proxyparams.proxyusername;           proxyparams.authentication.password := proxyparams.proxypassword;            onproxyauthorization(self, proxyparams.authentication, result);            if result begin             proxyparams.proxyusername := proxyparams.authentication.username;             proxyparams.proxypassword := proxyparams.authentication.password;           end           else begin             break;           end;         end;       end;     wndorequest:       begin         result := true;         break;       end;     wnfail:       begin         result := false;         break;       end;   end; until false; // *** changes start *** /// if result begin   response.keepalive := proxyparams.authentication.keepalive; end; ///*** changes end *** /// 

end; end;

still getting 407 proxy authorixation error. can 1 guide me on doing wrong ?

thanks in advance

try leaving out following line of code in idhttp1selectproxyauthorization method:

idhttp1.proxyparams.clear; 

in opinion, clears settings proxy, , that's why error.


Popular posts from this blog

Php - Delimiter must not be alphanumeric or backslash -

Delphi interface implements -