使用带有身份验证的 Web 服务总是给出消息 Authentication required

发布于 2024-10-07 13:37:26 字数 672 浏览 2 评论 0 原文

我尝试在 Delphi 2010 中使用消费一项 Web 服务。 此 Web 服务位于端口 8000 上并进行身份验证。

我实现了

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;

,但仍然有消息“需要身份验证”。

我做错了什么吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆梦 2024-10-14 13:37:26

对于基本身份验证,这应该有效:

Basic Authentication in Delphi 7 SOAP

如上所述在这篇文章中,较新版本的Delphi也允许使用

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

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;
林空鹿饮溪 2024-10-14 13:37:26

如果仍然不起作用,您可以尝试不同的客户端(.Net 或 Java),并借助本地代理(FiddlerDon's Proxy)或嗅探器 (WireShark),找出相关的差异。

If it still does not work, you can try a different client (.Net or Java), and compare the HTTP traffic with the help of a local proxy (Fiddler or Don's Proxy) or a sniffer (WireShark), to find the relevant differences.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文