Delphi Indy TIdHTTP将我的授权头从承载更改为基本?
德尔福XE7和印地10: 我正在尝试与需要的rest服务器通信 授权:持有人xxxxxxx 在HTTP调用的头中 我在代码中执行以下操作:Delphi Indy TIdHTTP将我的授权头从承载更改为基本?,delphi,https,authorization,indy,delphi-xe7,Delphi,Https,Authorization,Indy,Delphi Xe7,德尔福XE7和印地10: 我正在尝试与需要的rest服务器通信 授权:持有人xxxxxxx 在HTTP调用的头中 我在代码中执行以下操作: ... https.Request.Clear; https.Request.CustomHeaders.Clear; https.Request.BasicAuthentication:=false; https.Request.Accept:='application-json'; https.Reques
...
https.Request.Clear;
https.Request.CustomHeaders.Clear;
https.Request.BasicAuthentication:=false;
https.Request.Accept:='application-json';
https.Request.ContentType:='application/json';
token :=get_access_token;
Https.Request.CustomHeaders.AddValue('Authorization', 'Bearer '+token);
json :=https.post(base_api,reqjson);
就在POST之前,request.headers的内容是
(零,[],$31F28C0,#0,,#0,假,0,零,真,
((“授权:持有人XXXXXXXXXX…x”,无),(“,无),(”,
零,('',零)),1,4,假,重复忽略,假,(零,零),(零,零),
假“:”,真,真,2147483647,QuoteHTTP)
但当我检查idlog debug时,它显示:
邮寄XXXXXXXXXXXXXXXX
内容类型:application/json
内容长度:629
授权:基本XXXXXXXXXXXXX…xxx
主持人:XXXXXXXXXXXXXX
接受:应用程序json
接受编码:标识
用户代理:Mozilla/3.0(兼容;Indy Library)
好像持票人变成了基本的??如何避免这种情况?尝试使用
Https.Request.CustomHeaders.Values['Authorization']:='Bearer'+令牌代码>还设置Https.Request.CustomHeaders.foldline:=False代码>。由于您使用的是较旧的Delphi版本,因此可能值得升级到。然后我猜您的Indy版本太旧,您将不得不升级。。。(除非你展示的代码不是你真正的代码,问题在其他地方,我猜这就是为什么你的问题被否决的原因)总是包含一个。我自己解决问题。似乎当我不动态分配HTTP组件时,以前的调用在组件中留下了一些剩余内容,这些调用以某种方式禁用了对授权字段的更改。在我将其更改为“新的”动态分配的http组件后,它工作了。谢谢你的努力。真的fast@IbElfving仅供参考,目前正在开发一个新的tidbeareAuthentication
类,因此用户不再需要使用CustomHeaders
属性通过HTTP发送承载令牌。