Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

delphi - consuming web service with authentication allways give message Authentication required

I try to use consume one web service with Delphi 2010. This web service is on port 8000 with authentication.

I implement the

function TForm4.EncodeLoginPW(const ALogin, APW: string): string;
begin
  Result := EncdDecd.EncodeString(ALogin + ':' + APW); // EncdDecd is not documented in 
end;


procedure TForm4.HTTPRIO1HTTPWebNode1BeforePost(const HTTPReqResp: THTTPReqResp;
  Data: Pointer);
var
  s: string;
begin
  s := 'Authorization: Basic ' + EncodeLoginPW(UserName, Password);
  if not HttpAddRequestHeaders(Data, PChar(s), Length(s), HTTP_ADDREQ_FLAG_ADD) then
    ShowMessage('HttpAddRequestHeaders' + SysErrorMessage(GetLastError()));
end;

but I have still the message "Authentication required".

Do I make something wrong ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For Basic Authentication this should work:

Basic Authentication in Delphi 7 SOAP

As explained in this post, newer versions of Delphi also allow to use

HTTPRio.HTTPWebNode.UserName := Username;
HTTPRio.HTTPWebNode.Password := Password;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...