Short answer: your Pascal code isn't doing the same thing as the PHP version.
<?php
'client_id'=> '****',
'client_secret'=> '****',
'grant_type'=> 'password',
'username'=> '****',
'password'=> '****',
'scope' => 'minimax.rs');
...
http_build_query builds a url encoded string of the $params array, which will be:
client_id=%2A%2A%2A%2A%2A&client_secret=%2A%2A%2A%2A%2A&grant_type=password&username=%2A%2A%2A%2A%2A&password=%2A%2A%2A%2A%2A&scope=minimax.rs
and not:
{"client_id": "****", "client_secret": "****", "grant_type": "password", "username": "*****", "password": "*****", "scope": "minimax.rs"}
as in your Pascal code. One of the FormPost variant accepts TStrings, you can assign the params there and it will be encoded properly like this:
var
LParams: TStrings;
LResponse: String;
...
LParams := TStringList.Create;
LResponse := TStringList.Create;
with LParams do
try
Values['client_id'] := '****';
Values['client_secret'] := '*****';
... // and so on
LResponse := HTTPClient.FormPost(PostURL, LParams);
... // do something with LResponse
finally
LParams.Free;
end;
alternatively you can build the url encoded strings manually, but you have to EncodeURLElement() both the keys and values by hand.