[SOLVED] Problem converting curl to HTTP request

Hi all
I need to do this HTTP request:

curl -X POST -d "client_id=CLIENT_ID" -d "client_secret=CLIENT_SECRET" --data-urlencode "username=MY_USERNAME" --data-urlencode "password=MY_PASSWORD" -d 'grant_type=password' 'https://auth.contabo.com/auth/realms/contabo/protocol/openid-connect/token'

This is the function that is before the HTTP REQUEST (setup with POST):

msg.headers = {};
msg.headers['accept'] = 'application/json';
msg.headers['Content-Type'] = 'application/json';
msg.payload = {};
msg.payload.grant_type = 'password';
msg.payload.client_id = 'CLIENT_ID';
msg.payload.client_secret = 'CLIENT_SECRET';
msg.payload.username = encodeURIComponent('MY_USERNAME');
msg.payload.password = encodeURIComponent('MY_PASSWORD');
return msg;

But I keep getting the error:
{"error":"RESTEASY003065: Cannot consume content type"}

What am I doing wrong?

Set your content type to application/x-www-form-urlencoded

Thanks, that got me a step further, but now I get invalid credential.
The credentials are correct because I can use them to login to the website (yes, are the same credentials).
Maybe the problem is that using application/x-www-form-urlencoded encodes everything while the client_id and client_secret don't need to be encoded?

I just needed to do as @Steve-Mcl said and remove the encodeURIComponent for username and password :man_facepalming:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.