本文介绍了如何添加“ Authorization = Bearer”? Inphi中的Indy标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试使用access_token进行POST请求,并且使用POSTMAN可以正常工作,但是当我尝试在Delphi上执行相同的请求时,我找不到添加 Authorization = Bearer eyxxxxxx的方法...,就像POSTMAN一样。I'm trying to do a POST request using an access_token, and it works fine using POSTMAN, but when I try to do the same request on Delp I can't find a way to add the "Authorization=Bearer eyxxxxxx..." to the Request header, as POSTMAN does. POSTMAN请求(效果很好): POST / somepath HTTP / 1.1 主机:someurl.com.br 授权:Bearer eyJhbGciOiJSUzI1NiJ9 ..... 内容类型:application / jsonPOST /somepath HTTP/1.1Host: someurl.com.brAuthorization: Bearer eyJhbGciOiJSUzI1NiJ9.....Content-Type: application/json(省略了正文内容) 由Delphi生成的Indy请求,由HTTP分析器捕获(由于缺少 Authorization = Bearer部分,因此始终返回401 Forbidden错误): POST / somepath HTTP / 1.1 主持人:someurl.com.br 内容类型:application / jsonPOST /somepath HTTP/1.1Host: someurl.com.brContent-Type: application/json(省略正文)我尝试使用下面的代码添加标头,但是标有 Authorization = Bearer eyxxxxxx ...的标头部分不是并非根据请求生成,返回401禁止错误。I've tried to add the header using the code below, but the header part with the "Authorization=Bearer eyxxxxxx..." isn't generated on Request, returning the 401 Forbidden error.FIdHTTP.Request.CustomHeaders.FoldLines := False;FIdHTTP.Request.CustomHeaders.Add('Authorization=Bearer ' + txtToken.Text);推荐答案刚刚发现了问题。我在授权和承担者两个词之间添加了错误的分隔符。Just found the problem. I added the wrong separator between the "Authorization" and "Bearer" words. 错误:FIdHTTP.Request.CustomHeaders.FoldLines := False;FIdHTTP.Request.CustomHeaders.Add('Authorization=Bearer ' + txtToken.Text); 正确:FIdHTTP.Request.CustomHeaders.FoldLines := False;FIdHTTP.Request.CustomHeaders.Add('Authorization:Bearer ' + txtToken.Text);用':'代替'='之后,我收到了预期的响应,就像收到的一样通过邮递员。After replacing the '=' by ':', I received the expected response, like the one received by POSTMAN. 这篇关于如何添加“ Authorization = Bearer”? Inphi中的Indy标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-05 04:57