Unable to send rest sendPostRequest with content-type as application/x-www-form-urlencoded

Hei
I was trying to send rest sendPostRequest with content-type as application/x-www-form-urlencoded but every time i was getting http 400 with
{
error_description: ‘Invalid request: Missing “grant_type” parameter’,
error: ‘invalid_request’
}

below code snippet, I am using towards /token endpoint to get id_token.

var data = toUrlEncoded({
“grant_type”: “authorization_code”,
code: “somecode”,
“redirect_uri”: “https://buddid.co/
});

var response = await I.sendPostRequest(‘https://demo.myexample.azure.com/s2id/token’,
{data},
{
“Authorization”: “Basic xxxxxxxxxxxxxxxxxxxxxxxxxxx”,
“Content-Type”: “application/x-www-form-urlencoded”

});

console.log(response.data);
console.log(response.status);
console.log(response.statusText);
console.log(response.headers);
console.log(response.config);

debug message -

i found sendPostRequest method is not supporting application/x-www-form-urlencoded data ,its payload automatically converting to json format,something is wrong.I strongly believe that Content-Type" application/x-www-form-urlencoded is not supporting sendPostRequest method.Anyone has tried this before.

I noticed you have {data} try just data with no {}

1 Like