I am trying to use Indy to retrieve a RevContent oAuth token according to this page. Here is my code:
procedure TForm2.Button1Click(Sender: TObject);
var
IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocketOpenSSL;
idhttp:tidhttp;
params: TStringList;
begin
idhttp:=tidhttp.create(self);
IdSSLIOHandlerSocket1 := TIdSSLIOHandlerSocketOpenSSL.create(nil);
with IdSSLIOHandlerSocket1 do begin
SSLOptions.Method := sslvSSLv23;
SSLOptions.SSLVersions := [sslvSSLv23];
end;
params := TStringList.create;
params.add('clientid=xxyyzz');
params.add('client_secret=xxyyzzxxyyzzxxyyzzxxyyzzxxyyzzxxyyzz');
params.add('grant_type=client_credentials');
with IdHTTP do begin
IOHandler := IdSSLIOHandlerSocket1;
Request.ContentType := 'application/x-www-form-urlencoded';
end;
showmessage(idhttp.Post('https://api.revcontent.io/oauth/token',params));
end;
But whenever I run it I get an 400 Bad Request error. What am I doing wrong?
Use client_id
, not clientid
.
Do not use SSL3, that site supports TLS1.
Do not set ContentType.
Use try/except around Post
to catch exception and get full error message (E as EIdHTTPProtocolException).ErrorMessage