# How to send a post request with content

**URL:** <https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537>\
**Category:** General\
**Created:** [14 September 2019 16:44 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537 "2019-09-14T16:44:23Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cybertron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cybertron/32/14683_2.png) [@Cybertron](https://discourse.nodered.org/u/Cybertron)\
**Post date:** [14 September 2019 16:44 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/1 "2019-09-14T16:44:23Z")

</div>

I want to use a button to trigger a post request with additional content, how to achieve it

 ![ssss](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b10f6e9fb6672b118a11d319530683d34f4a3c50.png)  
As shown in the figure, it contains multiple headers and a JSON content

---

<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:** [14 September 2019 17:20 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/2 "2019-09-14T17:20:12Z")

</div>

Inject (or button) --\> change node (set `msg.payload` to JSON with your content) --\> http out node (set to post and add any headers you need)

The change node will push the JSON to the http out node via `msg.payload`

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [14 September 2019 18:01 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/3 "2019-09-14T18:01:16Z")

</div>

> [@Steve-Mcl](#):
>
> http out node (set to post and add any headers you need)

Just for further clarification, that’s the “HTTP request” node. HTTP-in and HTTP-response are used for serving content through flows.

---

<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:** [14 September 2019 18:10 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/4 "2019-09-14T18:10:32Z")

</div>

Good catch.

---

<div class="post-metadata">

**Author:** ![Cybertron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cybertron/32/14683_2.png) [@Cybertron](https://discourse.nodered.org/u/Cybertron)\
**Post date:** [15 September 2019 08:32 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/5 "2019-09-15T08:32:46Z")

</div>

Very good. I have achieved my goal. Thank you very much.

---

<div class="post-metadata">

**Author:** ![Cybertron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cybertron/32/14683_2.png) [@Cybertron](https://discourse.nodered.org/u/Cybertron)\
**Post date:** [16 December 2019 14:22 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/6 "2019-12-16T14:22:35Z")

</div>

Hello, I have a new problem

 ![6ceead9a91f6dae77bfecd05d48afbdebea1176a](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6ceead9a91f6dae77bfecd05d48afbdebea1176a.png)  
I use HTTP nodes to post data in node-red, but the annotated places are not valid json data, so I tried many methods

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [16 December 2019 14:24 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/7 "2019-12-16T14:24:02Z")

</div>

check the content type in your screenshot, and start there.

---

<div class="post-metadata">

**Author:** ![Cybertron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cybertron/32/14683_2.png) [@Cybertron](https://discourse.nodered.org/u/Cybertron)\
**Post date:** [16 December 2019 14:32 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/8 "2019-12-16T14:32:10Z")

</div>

![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/24a2d66cffde82543e49e4da25f3f5a38bb86f48.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b8230237b508b5544d91d32f47f348093aff113f.png)

I used the Google browser developer tool to view the form data and then used the HTTP node at node-red. I had filled in the request header, but the form data would not be submitted

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [16 December 2019 14:33 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/9 "2019-12-16T14:33:35Z")

</div>

I think you're using the wrong node. The one in your second screenshot is the HTTP Response node. You're looking for the HTTP Request node, and set headers to it through a change node to `msg.headers`, or a function node doing the same.

---

<div class="post-metadata">

**Author:** ![Cybertron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cybertron/32/14683_2.png) [@Cybertron](https://discourse.nodered.org/u/Cybertron)\
**Post date:** [16 December 2019 14:48 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/10 "2019-12-16T14:48:43Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/da451ea142bcdc8bd46d38324a01f7a6bb598b94.png)  
I rearranged the process, but it didn't get me where I wanted to go

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [16 December 2019 14:53 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/11 "2019-12-16T14:53:26Z")

</div>

without knowing how the rest of your flow looks like I can't give you much advice on that... On top of that, I'm far from sure that hardcoding the session cookie would be a good idea. Better would it be to have the login process done in node-red as well, save the return cookies and use those going forward.

---

<div class="post-metadata">

**Author:** ![Cybertron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cybertron/32/14683_2.png) [@Cybertron](https://discourse.nodered.org/u/Cybertron)\
**Post date:** [16 December 2019 14:57 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/12 "2019-12-16T14:57:09Z")

</div>

Aha, I will not set the login and save the cookie, but I have tested it for a day, and the same cookie can be used in multiple IP addresses. I am not sure whether there will be any problem in the future. I provided the json file during the learning stage, please check if you have time[flows 6.0.json](https://discourse.nodered.org/uploads/short-url/A83cRhGqhvU0e4Etr05tW8wkSUg.json) (56.0 KB)

---

<div class="post-metadata">

**Author:** ![anitagrants](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@anitagrants](https://discourse.nodered.org/u/anitagrants)\
**Post date:** [4 August 2020 05:49 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/13 "2020-08-04T05:49:40Z")

</div>

you can send it with ReqBin, quickly and easily, right from your browser.

---

<div class="post-metadata">

**Author:** ![rakgupta](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rakgupta/32/42535_2.png) [@rakgupta](https://discourse.nodered.org/u/rakgupta)\
**Post date:** [19 August 2020 23:38 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/14 "2020-08-19T23:38:05Z")

</div>

> [@afelix](#):
>
> save the return cookies and use those going forward

Hello - I'm trying to do exactly this but I am not sure how to use the saved cookies in the next http request node. I can have Nodered log in and I can see the cookies being returned in message.responseCookie. Any guidance on how to use that in the next http request would be really appreciated. I'm somewhat of a novice so please be patient 🙂

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [20 August 2020 06:19 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/15 "2020-08-20T06:19:24Z")

</div>

Take a look at the docs for the `http-request` node. It says that the cookies from the request come back as `msg.responseCookies`, but to put them on a request you need `msg.cookies`. So you put a change node in between, and make something that sets responseCookies to cookies. I do so with JSONata, and if needed merge it with an existing set of cookies: Set `msg.cookies` to `$exists($.cookies) ? $merge([cookies, responseCookies]) : responseCookies`  
It checks if `msg.cookies` is already defined and if so merges the cookies object with the incoming responseCookies, and if not sets the cookies to responseCookies.

---

<div class="post-metadata">

**Author:** ![rakgupta](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rakgupta/32/42535_2.png) [@rakgupta](https://discourse.nodered.org/u/rakgupta)\
**Post date:** [20 August 2020 13:11 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/16 "2020-08-20T13:11:12Z")

</div>

Thanks for the response @afelix. I tried the following and I don't think it is working... below is the test flow:

 ![Screen Shot 2020-08-20 at 7.52.17 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/7747dab6c93bbcd832f81abde867205f5410177c.png)

I can see the cookie returned from the first http request node

> **Cookie in first login/response - msg.responseCookies**
>
> {"HUBSESSION":{"Path":"/","value":"node086xpcac4lcdvi67wbof0gyj871.node0"}}

In the function node, I set msg.cookies to msg.responseCookies

> **Function node**
>
> var cookies = msg.responseCookies;  
> msg.headers={};  
> msg.cookies = cookies;  
> return msg;

The output of the function node is:

> **Function Node output - msg.cookies**
>
> {"HUBSESSION":{"Path":"/","value":"node086xpcac4lcdvi67wbof0gyj871.node0"}}

The second http request node is supposed to use this cookie and download a file (currently I have it set to UTF-8 string, but normally it would be binary)

 ![Screen Shot 2020-08-20 at 7.08.05 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/d/6dd6168413c6bd4d797ddc3feae770ca35fa7a66.png)  
When I look at the return http headers from this request, there is a different value in cookie?

> **http header**
>
> {"connection":"close","date":"Thu, 20 Aug 2020 12:48:03 GMT","set-cookie":["HUBSESSION=\*\*node0149tbnewmz54xbtn971u3a20m72.node0;\*\*Path=/"],"expires":"Thu, 01 Jan 1970 00:00:00 GMT","x-frame-options":"DENY","content-type":"text/html;charset=utf-8","server":"Jetty(9.4.z-SNAPSHOT)","x-node-red-request-node":"007887aa"}

I have a curl script (copied from someone else - I don't know curl) that does this and it works - just trying to make it work with Node-red

> **Curl Script**
>
> curl -c cookie.txt -d "username=USERNAME" -d "password=PASSWORD" http://HUB\_IP/login  
> curl -sb cookie.txt http://HUB\_IP/hub/backupDB?fileName=latest -o "/Users/NAME/Documents/Hubitat\_Backup/Hubitat\_Backup.lzf"

Thanks for any pointers..

---

<div class="post-metadata">

**Author:** ![JeroenKokhuis](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@JeroenKokhuis](https://discourse.nodered.org/u/JeroenKokhuis)\
**Post date:** [26 August 2020 10:35 UTC](https://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537/17 "2020-08-26T10:35:17Z")

</div>

Hello,

I've also a problem with my garbage collector date.  
This is the Url:

[https://www.rova.nl/api/TrashCalendar/GetCalendarItems?portal=inwoners](https://www.rova.nl/api/TrashCalendar/GetCalendarItems?portal=inwoners)

And this is the cookie:

```auto
RovaLc_inwoners={"Id":XXXXX,"ZipCode":"XXXXX","HouseNumber":"XX","HouseAddition":"","Municipality":"XXXXXXXXX","Province":null,"Firstname":null,"Lastname":null,"UserAgent":"","School":null,"Street":"Schout Doddestraat","IsRovaArea":true,"Country":null,"Portal":null,"Lat":"XXXXXXXXX","Lng":"XXXXXXX667","AreaLevel":X,"City":"XXXXXXXXXX","Ip":null}

```

I have read the above but I can't find a solution. I tried with the change node (set msg.payload to JSON with my content) but it's not valid JSON content.

And how to add the header to the http request node?

HTTP POST doesn't work this is the error:

```auto
payload: "{"Message":"The requested resource does not support http method 'POST'."}"

```
