Hi everyone,
I'm trying to develop a function with AL that permits to Post a url encoded content.

It works fine with postman. The following procedure that I've started developping doesn't work :
procedure GetToken() ResponseText: text;
Var
client: HttpClient;
cont: HttpContent;
header: HttpHeaders;
response: HttpResponseMessage;
Jobject: JsonObject;
tmpString: Text;
TypeHelper: Codeunit "Type Helper";
granttype: text;
clienid: text;
username: text;
password: text;
Begin
granttype := 'xxxxx';
clienid := 'xxxxxx';
username := 'xxxxxxxxx';
password := 'xxxxxxxxxxxxx';
Jobject.Add('grant_type', TypeHelper.UrlEncode(granttype));
Jobject.Add('client_id', TypeHelper.UrlEncode(clienid));
Jobject.Add('username', TypeHelper.UrlEncode(username));
Jobject.Add('password', TypeHelper.UrlEncode(password));
Jobject.WriteTo(tmpString);
cont.WriteFrom(tmpString);
cont.ReadAs(tmpString);
cont.GetHeaders(header);
header.Add('charset', 'UTF-8');
header.Remove('Content-Type');
header.Add('Content-Type', 'application/x-www-form-urlencoded');
client.Post('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', cont, response);
response.Content.ReadAs(ResponseText);
end;
Can someone help me please?
I get this response everytime :
{
"error": "invalid_request",
"error_description": "Missing form parameter: grant_type"
}
Ps : it doesn't work even without encoding the parameters.
Thanks in advance