Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node-red HTTP POST parameters

Can someone help me translate this working curl command into a node-red POST command?

curl -X POST http://URL -H "Authorization: 123123123" -d "subjectUid=789789789"

Here's my partially working function node which creates the parameters and pushes to a http node:

msg.headers = {};
msg.headers={ 
    'Authorization':  '123123123'
};

msg.payload = {};
msg.payload={ 
    'subjectUid': '789789789'
};

return msg

The auth token is accepted, but the server replies that the subjectUid is not set. What am I doing wrong?

like image 340
Dalhousie Avatar asked Feb 03 '26 16:02

Dalhousie


1 Answers

This will be that by default the post message will forward on the JSON representation of the msg.payload object, what you want is the form encoding.

Try adding the following header:

msg.headers = {};
msg.headers={ 
    'Authorization':  '123123123',
    'Content-Type': 'application/x-www-form-urlencoded'
};

msg.payload = {};
msg.payload={ 
    'subjectUid': '789789789'
};

return msg
like image 133
hardillb Avatar answered Feb 06 '26 06:02

hardillb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!