3
Delphi 7에서 Indy 10 Components로 NTLM 인증을하고 싶습니다. 가 여기 내 소스 코드입니다 : 내가 인터넷에서 읽은 내용으로 당Delphi 7에서 Indy 10을 사용하여 NTLM 인증을 수행하는 방법은 무엇입니까?
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 it to True , No Changes in error
End;
procedure TForm1.IdHTTP1SelectProxyAuthorization(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', idHTTP1.Response.RawHeaders.Text)>0) then
begin
idHTTP1.ProxyParams.Clear;
idHTTP1.ProxyParams.BasicAuthentication := false;
// Set the authentication class to NTLM
//idhttp1.auth
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', idHTTP1.Response.RawHeaders.Text)>0) then
AuthenticationClass := TIdDigestAuthentication
end;
end;
idHTTP1.ProxyParams.ProxyUsername := 'xxxx';
idHTTP1.ProxyParams.ProxyPassword := 'xxxx';
end;
, 또한 다음 IdHttp.pas의 소스 코드를 수정 : -
function TIdCustomHTTP.DoOnProxyAuthorization(ARequest: TIdHTTPRequest; AResponse: TIdHTTPResponse): Boolean;
var
i: Integer;
S: string;
Auth: TIdAuthenticationClass;
begin
Inc(FAuthProxyRetries);
if not Assigned(ProxyParams.Authentication) then
begin
// Find which Authentication method is supported from us.
i := 0;
while i < AResponse.ProxyAuthenticate.Count do
begin
S := AResponse.ProxyAuthenticate[i];
try
Auth := FindAuthClass(Fetch(S));
break;
except
end;
inc(i);
end;
if i = AResponse.ProxyAuthenticate.Count then
begin
result := false;
exit;
end;
if Assigned(FOnSelectProxyAuthorization) then
begin
OnSelectProxyAuthorization(self, Auth, AResponse.ProxyAuthenticate);
end;
{ ProxyParams.Authentication := Auth.Create;
end;
result := Assigned(OnProxyAuthorization);
// Clear password and reset autorization if previous failed
if (AResponse.FResponseCode = 407) then begin
ProxyParams.ProxyPassword := '';
ProxyParams.Authentication.Reset;
end; }
/// *** Changes Start **** ////
if Assigned(Auth) then
begin
ProxyParams.Authentication := Auth.Create;
end;
end;
result := Assigned(ProxyParams.Authentication) and Assigned(OnProxyAuthorization);
// Clear password and reset autorization if previous failed
if ((AResponse.FResponseCode = 407) and
(not (ProxyParams.Authentication is TIdSSPINTLMAuthentication))) then
begin
ProxyParams.ProxyPassword := '';
if Assigned(ProxyParams.Authentication) then
begin
ProxyParams.Authentication.Reset;
end;
End;
//// **** Changes end *** /////
if Result then
begin
with ProxyParams.Authentication do
begin
Username := ProxyParams.ProxyUsername;
Password := ProxyParams.ProxyPassword;
AuthParams := AResponse.ProxyAuthenticate;
end;
result := false;
repeat
case ProxyParams.Authentication.Next of
wnAskTheProgram: // Ask the user porgram to supply us with authorization information
begin
if Assigned(OnProxyAuthorization) then
begin
ProxyParams.Authentication.Username := ProxyParams.ProxyUsername;
ProxyParams.Authentication.Password := ProxyParams.ProxyPassword;
OnProxyAuthorization(self, ProxyParams.Authentication, result);
if result then 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 then
begin
Response.KeepAlive := ProxyParams.Authentication.KeepAlive;
end;
///*** Changes End *** ///
끝을; 끝;
여전히 프록시 설치 오류가 발생합니다. 어떤 사람이 내가 뭘 잘못하고 있는지 안내 할 수 있습니까? 사전에
감사
다른 인증 클래스 TIdNTLMAuthentication; – Copilot