# \[SOLVED\] Problem converting curl to HTTP request

**URL:** <https://discourse.nodered.org/t/solved-problem-converting-curl-to-http-request/80352>\
**Category:** General\
**Tags:** http-request\
**Created:** [6 August 2023 15:18 UTC](https://discourse.nodered.org/t/solved-problem-converting-curl-to-http-request/80352 "2023-08-06T15:18:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andre\_x](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@andre\_x](https://discourse.nodered.org/u/andre_x)\
**Post date:** [6 August 2023 15:18 UTC](https://discourse.nodered.org/t/solved-problem-converting-curl-to-http-request/80352/1 "2023-08-06T15:18:22Z")

</div>

Hi all  
I need to do this HTTP request:

```auto
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):

```auto
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?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 August 2023 20:57 UTC](https://discourse.nodered.org/t/solved-problem-converting-curl-to-http-request/80352/2 "2023-08-06T20:57:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andre\_x](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@andre\_x](https://discourse.nodered.org/u/andre_x)\
**Post date:** [6 August 2023 21:15 UTC](https://discourse.nodered.org/t/solved-problem-converting-curl-to-http-request/80352/3 "2023-08-06T21:15:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![andre\_x](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@andre\_x](https://discourse.nodered.org/u/andre_x)\
**Post date:** [11 August 2023 14:10 UTC](https://discourse.nodered.org/t/solved-problem-converting-curl-to-http-request/80352/4 "2023-08-11T14:10:28Z")

</div>

I just needed to do as @Steve-Mcl said and remove the encodeURIComponent for username and password 🤦‍♂️

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 October 2023 14:10 UTC](https://discourse.nodered.org/t/solved-problem-converting-curl-to-http-request/80352/5 "2023-10-10T14:10:37Z")

</div>

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