简体   繁体   中英

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 ?

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;

如果仍然无法正常工作,则可以尝试使用其他客户端(.Net或Java),并在本地代理( FiddlerDon's Proxy )或嗅探器(WireShark)的帮助下比较HTTP流量,以找到相关的区别。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM