在Delphi 10.3中使用HTTPRIO进行基本身份验证 [英] Basic authentication with HTTPRIO in Delphi 10.3

查看:125
本文介绍了在Delphi 10.3中使用HTTPRIO进行基本身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Delphi 10.3中,对 HTTPRIO.HTTPWebNode.OnBeforePost 事件进行了更改.

There has been a change to the HTTPRIO.HTTPWebNode.OnBeforePost event in Delphi 10.3.

在Delphi 10.3之前,事件处理程序是以这种方式定义的,并且可以完美地工作:

Before Delphi 10.3, the event handler was defined this way, and it worked perfectly:

procedure TForm1.HTTPRIO1HTTPWebNode1BeforePost(const HTTPReqResp: THTTPReqResp;
  Data: Pointer);
var
  auth: String;
begin
  auth := 'Authorization: Basic ' + IdEncoderMIME1.EncodeString('user:password');
  HttpAddRequestHeaders(Data, PChar(auth), Length(auth), HTTP_ADDREQ_FLAG_ADD);
end;

在Delphi 10.3中, Data 参数消失了,取而代之的是 THTTPClient ,我不知道如何使用它实现基本身份验证:

In Delphi 10.3, the Data parameter is gone, instead a THTTPClient is given, and I have no idea how to implement Basic authentication with it:

procedure TForm1.HTTPRIO1HTTPWebNode1BeforePost(const HTTPReqResp: THTTPReqResp;
  Client: THTTPClient);
var
  auth: String;
begin
  auth := 'Authorization: Basic ' + IdEncoderMIME1.EncodeString('user:password');
  ???
end;

有任何提示吗?

推荐答案

尝试使用请求的 用户名

Try using the request's Username and Password properties, eg:

HTTPReqResp.UserName := 'user';
HTTPReqResp.Password := 'password';

如果这不起作用,请尝试使用客户端的 CustomHeaders 属性,例如:

If that does not work, try using the client's CustomHeaders property instead, eg:

Client.CustomHeaders['Authorization'] := 'Basic ' + IdEncoderMIME1.EncodeString('user:password');

这篇关于在Delphi 10.3中使用HTTPRIO进行基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆