Using Post http request to get data feed into node-red

3,506 views
Skip to first unread message

Paul Reed

unread,
Sep 16, 2014, 3:38:09 PM9/16/14
to node...@googlegroups.com
I'm trying to import a json string into node-red, sent via curl every 5 minutes from another source within Localhost, but have found googling http requests a painful experience!

I have set a http request input node to receive the data on /heating and wired a debug node for testing.
Opened up port 1880 on my router, but am struggling with formatting the http string format to post the data. So far I have:

http://mydomain.co.uk:1880/heating?json={temp:28}&user=username&pass=password    //(I'm using Basic Authentication in node-red)

..which I'm sure you'll probably already realize that it doesn't work!


Paul

Anupam Datta

unread,
Sep 17, 2014, 5:53:44 AM9/17/14
to node...@googlegroups.com
May be I haven't understood your problem. Are you doing something like You are POSTing data into one PORT and listening that PORT from another node ?

Is that the simplest version of your wiring?

[{"id":"72a297cf.8d5d68","type":"inject","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":127,"y":3739,"z":"46218709.b9de78","wires":[["56984339.a967bc"]]},{"id":"56984339.a967bc","type":"tcp out","host":"","port":"","beserver":"client","base64":false,"end":false,"name":"","x":352,"y":3740,"z":"46218709.b9de78","wires":[]},{"id":"49ab1db.fb654e4","type":"tcp in","server":"server","host":"","port":"","datamode":"stream","datatype":"buffer","newline":"","topic":"","name":"","base64":false,"x":116,"y":3830,"z":"46218709.b9de78","wires":[["8c7f48be.7380b8"]]},{"id":"8c7f48be.7380b8","type":"debug","name":"","active":true,"console":"false","complete":"false","x":331,"y":3820,"z":"46218709.b9de78","wires":[]}]

Nicholas O'Leary

unread,
Sep 17, 2014, 5:58:33 AM9/17/14
to node...@googlegroups.com
HI Paul,

assuming you have set the HTTPInput node to list for POST requests, the following curl invocation can be used to send data to it:


    $ curl -X POST -d '{"a":1,"b":2}' -u username:password -H "Content-Type: application/json" http://mydomain.co.uk:1880/heating

Points to note:
 - the JSON string you want to send is specified by the -d parameter
 - you must set the Content-Type header to application/json so the HTTP node knows to parse it as such
 - username/password for basic auth are specified with the -u parameter

Nick



--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lawrence Griffiths

unread,
Sep 17, 2014, 1:01:40 PM9/17/14
to node...@googlegroups.com
For those who, like me, aren't a wiz with CURL and use Chrome tryout POSTMAN
I has a nice history feature which holds not only URL but the request data to.

Paul Reed

unread,
Sep 17, 2014, 5:17:00 PM9/17/14
to node...@googlegroups.com
I appreciate the advice guys, I've now got it working (in a fashion!) and just need to sort out the parsing and data processing.
The Chrome app & the weblink are both really useful to ensure everything is as it should be.

Thanks Again.

Paul
Reply all
Reply to author
Forward
0 new messages