请帮助我弄清楚如何正确地编写 Delphi 代码,以匹配运行Curl POST命令的结果,而不指定主体。
我能够成功运行CURL命令,它按预期返回帐户信息:
curl -X POST https://api.dropboxapi.com/2/users/get_current_account\
--header "Authorization: Bearer <get access token>"
字符串
然而,当我尝试为它编写 Delphi 代码时:
RESTClient:=TRESTClient.Create('https://api.dropboxapi.com');
RESTRequest:=TRESTRequest.Create(RESTClient);
RESTClient.Authenticator:= OAuth2.OAuth2Authenticator;
RESTRequest.Method := TRESTRequestMethod.rmPOST;
RESTRequest.Resource := '/2/users/get_current_account';
RESTRequest.Params.Clear;
RESTRequest.Params.AddHeader('Authorization','Bearer '+OAuth2.AccessToken);
RESTRequest.AddParameter('Content-Type', 'text/plain; charset=dropbox-cors-hack', pkHTTPHEADER,[poDoNotEncode]);
RESTRequest.ClearBody; //aparently it doesn't translate into sending a completely empty body
RESTRequest.OnHTTPProtocolError := ProcessException;
try
RESTRequest.Execute;
except
on E:...
end;
型
我得到以下回应:
Error in call to API function "users/get_current_account": request body: could not decode input as JSON
型
我还尝试用这两行来更改Content-Type行:
RESTRequest.AddParameter('Content-Type', 'application/json', pkHTTPHEADER, [poDoNotEncode]);
RESTRequest.Params.AddBody('',TRESTContentType.ctAPPLICATION_JSON);
型
或者用这两条线:
RESTRequest.AddParameter('Content-Type', 'application/json', pkHTTPHEADER, [poDoNotEncode]);
RESTRequest.Params.AddBody('{}',TRESTContentType.ctAPPLICATION_JSON);
型
结果是一样的:
Error in call to API function "users/get_current_account": request body: could not decode input as JSON
型
我已经浪费了1天试图弄清楚它,请帮助我与此...
1条答案
按热度按时间6qfn3psc1#
在浪费了更多的时间之后,我找到了答案:
字符串
希望它能帮助其他人不要在这个问题上浪费更多的时间。