Indy 10 in Lazarus RingCentral API RingOut TIdHTTP

问题描述

拉撒路1.8.4
Indy 10(2020年3月)
Windows Server 2016

我正在尝试为我在Lazarus中建立的联系人列表构建一个小的“拨号程序”模块。经过几个月的摸索,我终于能够将所有RingCentral API设置转换为Postman,然后转换为Indy HTTP设置,以完成令牌的获取。该部分工作可靠。但是,我无法执行RingOut API。我总是找不到404。 RingCentral在其文档中提供的其他编程语言中的示例无法很好地转换为Indy。

if htpCall.Connected then
  htpCall.Request.Connection := 'close';  // Close the socket after using it to obtain the token
htpCall.Request.Clear;

htpCall.Request.Accept := 'application/json';
htpCall.Request.ContentType := 'application/json';
htpCall.Request.Username := '<redacted>';   // Client ID
htpCall.Request.Password := '<redacted>';   //  Client Secret
htpCall.Request.CustomHeaders.Clear;
htpCall.Request.CustomHeaders.FoldLines := False;
htpCall.Request.BasicAuthentication := False;
htpCall.Request.CustomHeaders.AddValue('Authorization','Bearer ' + acc_tkn);

prms_lst.Add('from=<redacted>');
prms_lst.Add('to=<redacted>');
prms_lst.Add('callerId=<redacted>');
prms_lst.Add('country=Canada');
prms_lst.Add('playPrompt=true');

// Remove the text ".devtest" for the production version of your code,and replace the phone account with the real main phone number
htpCall.Post('https://platform.devtest.ringcentral.com/restapi/v1.0/account/<redacted>/extension/101/ring-out',prms_lst);

更新:

如果我将TIdHTTP保持打开状态,然后运行上面的代码,则会收到其他错误

已发送:

POST /restapi/v1.0/account//extension/101/ring-out HTTP/1.1
Content-Type: application/json
Content-Length: 82
Authorization: Basic 
Host: platform.devtest.ringcentral.com
Accept: application/json
User-Agent: Mozilla/3.0 (compatible; Indy Library)


from=&to=&callerId=&country=Canada&playPrompt=true

Rcvd:

HTTP/1.1 401 Unauthorized
Server: Nginx
Date: Tue,25 Aug 2020 01:50:24 GMT
Content-Type: application/json
Content-Length: 175
Connection: keep-alive
WWW-Authenticate: Bearer realm="RingCentral REST API"
RCRequestId: 57c97008-e675-11ea-87cf-005056bb81b6

{
  "errorCode" : "AGW-402","message" : "Invalid Authorization header","errors" : [ {
    "errorCode" : "AGW-402","message" : "Invalid Authorization header"
  } ]
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)