# Help needed for https POST / cookie

**URL:** <https://discourse.nodered.org/t/help-needed-for-https-post-cookie/32630>\
**Category:** General\
**Created:** [9 September 2020 09:24 UTC](https://discourse.nodered.org/t/help-needed-for-https-post-cookie/32630 "2020-09-09T09:24:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomy123](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@thomy123](https://discourse.nodered.org/u/thomy123)\
**Post date:** [9 September 2020 09:24 UTC](https://discourse.nodered.org/t/help-needed-for-https-post-cookie/32630/1 "2020-09-09T09:24:08Z")

</div>

Hi all

I would like to read data out of a water softener (BWT Aqua Perla) which has a webinterface in my own LAN. Therefore its needed as a first step to login through POST request to gain the cookie. The cookie is from CAKEPHP. Then a second call to another site on the webapp should return a json string. Nevertheless, I‘m facing the issue, i get the cookie, transfer it to second http request, but it returns a 302 error, indicating that a url redirect happens. msg. payload relay as well on login page...

do you have any ideas, how I can change the second call to get the json information?

The way should be as this:

Login:  
Post Request to [http://xx.xx.xx.xx/users/login](http://xx.xx.xx.xx/users/login) with Content "\_method=POST&STLoginPWField=xxxxxx&function=s ave"

—\> Response-Cookie "CAKEPHP"

Getting the data with url:  
/home/actualizedata

—\>response  
{"aktuellerDurchfluss":"0","aktuellerDurchflussProzent":"0","durchflussHeute":"0","durchflussMonat":"0","durchflussJahr":"0","RegeneriemittelNachfuellenIn":"0","RegeneriemittelVerbleibend":"0"}

This is the code for the nodes.

```auto
[{"id":"da556b4c.191f68","type":"tab","label":"BWT Perla Seta","disabled":false,"info":""},{"id":"7d4a8e14.598fd","type":"debug","z":"da556b4c.191f68","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"responseUrl","targetType":"msg","statusVal":"","statusType":"auto","x":1170,"y":240,"wires":[]},{"id":"718329ef.af2aa","type":"inject","z":"da556b4c.191f68","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":340,"wires":[["7b705cf5.8d7644"]]},{"id":"fc22ddec.3cea4","type":"debug","z":"da556b4c.191f68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"responseCookies","targetType":"msg","statusVal":"","statusType":"auto","x":760,"y":160,"wires":[]},{"id":"7b705cf5.8d7644","type":"function","z":"da556b4c.191f68","name":"","func":"msg.headers = \n{ \"Content-Type\" : \"application/x-www-form-urlencoded\" ,\n\"Origin\": \"https://192.168.1.189\",\n\"Host\": \"192.168.1.189\",\n\"Referer\": \"https://192.168.1.189/users/login\",\n\"Upgrade-Insecure-Requests\": \"1\",\n\"STLoginPWField\": \"dzfuqv\",\n\"function\":\"save\"}\nmsg.rejectUnauthorized = false;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":240,"wires":[["52fd04b6.7857ac"]]},{"id":"52fd04b6.7857ac","type":"http request","z":"da556b4c.191f68","name":"login","method":"POST","ret":"txt","paytoqs":"ignore","url":"https://192.168.1.189/","tls":"","persist":false,"proxy":"","authType":"","x":450,"y":240,"wires":[["fc22ddec.3cea4","b5f435fd.62b8"]]},{"id":"b5f435fd.62b8","type":"function","z":"da556b4c.191f68","name":"","func":"msg.headers = {\n \"Host\": \"192.168.1.189\",\n \"Upgrade-Insecure-Requests\": 1,\n \"STLoginPWField\": \"dzfuqv\",\n \"function\":\"save\"\n};\nmsg.cookies = msg.responseCookies;\nmsg.rejectUnauthorized = false;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":735.3333129882812,"y":240.33334350585938,"wires":[["c330713d.f7513","7a461eae.0028c"]]},{"id":"c330713d.f7513","type":"http request","z":"da556b4c.191f68","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://192.168.1.189/home/actualizedata/","tls":"","persist":false,"proxy":"","authType":"","x":950,"y":240,"wires":[["7d4a8e14.598fd","9621282.0604158","853b6de9.7ecd5"]]},{"id":"7a461eae.0028c","type":"debug","z":"da556b4c.191f68","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"cookies","targetType":"msg","statusVal":"","statusType":"auto","x":960,"y":400,"wires":[]},{"id":"9621282.0604158","type":"debug","z":"da556b4c.191f68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1160,"y":380,"wires":[]},{"id":"853b6de9.7ecd5","type":"debug","z":"da556b4c.191f68","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"cookies","targetType":"msg","statusVal":"","statusType":"auto","x":1150,"y":180,"wires":[]}]

```

Thanks a lot for your assist  
Thomas

---

<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:** [9 September 2020 11:31 UTC](https://discourse.nodered.org/t/help-needed-for-https-post-cookie/32630/2 "2020-09-09T11:31:44Z")

</div>

I am reading from mobile so I haven’t imported your flow but read the function node. Can you explain what you’re trying to accomplish by putting the payload you’re posting

> [@thomy123](#):
>
> "\_method=POST&STLoginPWField=xxxxxx&function=s ave"

In the headers, rather than in msg.payload?  
I think the issue of the redirect might be that the session cookie that is returned to you might be for a session that failed to log in.

---

<div class="post-metadata">

**Author:** ![thomy123](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@thomy123](https://discourse.nodered.org/u/thomy123)\
**Post date:** [9 September 2020 12:25 UTC](https://discourse.nodered.org/t/help-needed-for-https-post-cookie/32630/3 "2020-09-09T12:25:11Z")

</div>

hi afelix

thanks for your prompt answer. The first try was to use standard login from request node, but, the webapp has not a valid ssl certificate (given from BWT) so i had to do a workaround. I traced the login procedure with firefox to see the steps in between as curl, and googled how to to that with nodered..

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/4/844a815bbaba61044a98eeda317320a7ad71778a.png)

after login i get the cookie "CAKEPHP"  
and should send this cookie with the next request to: ../home/actualizedata

to catch the json.

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/3/6308f3e27bdebc96fd09e464ddb3334369130f89.png)

I will rewrite the node with your idea to payload, but still no luck.

```auto
msg.headers = 
{ "Content-Type" : "application/x-www-form-urlencoded" ,
"Origin": "https://192.168.1.189",
"Host": "192.168.1.189",
"Referer": "https://192.168.1.189/users/login",
"Upgrade-Insecure-Requests": "1"
}
msg.payload = {
    "STLoginPWField": "dzfuqv",
    "function":"save"}
msg.rejectUnauthorized = false;
return msg;

```

Thanks a lot  
Thomas

---

<div class="post-metadata">

**Author:** ![thomy123](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@thomy123](https://discourse.nodered.org/u/thomy123)\
**Post date:** [9 September 2020 12:52 UTC](https://discourse.nodered.org/t/help-needed-for-https-post-cookie/32630/4 "2020-09-09T12:52:28Z")

</div>

I incorporated the curl POST script here as well. Probably that helps.

```auto
curl "https://192.168.1.189/users/login" 
-H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0" 
-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" 
-H "Accept-Language: de,en-US;q=0.7,en;q=0.3" 
--compressed 
-H "Content-Type: application/x-www-form-urlencoded" 
-H "Origin: https://192.168.1.189" 
-H "Connection: keep-alive" 
-H "Referer: https://192.168.1.189/users/login" 
-H "Cookie: CAKEPHP=977fde0f224f2bf83db5e47a02303b71" 
-H "Upgrade-Insecure-Requests: 1" 
--data-raw "_method=POST&STLoginPWField=dzfuqv&function=save"

```

---

<div class="post-metadata">

**Author:** ![thomy123](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@thomy123](https://discourse.nodered.org/u/thomy123)\
**Post date:** [9 September 2020 16:47 UTC](https://discourse.nodered.org/t/help-needed-for-https-post-cookie/32630/5 "2020-09-09T16:47:59Z")

</div>

Hi

filling msg.payload does the trick finally. See code below.

```auto
[{"id":"56efe5dc.c6ddac","type":"debug","z":"da556b4c.191f68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":340,"wires":[]}]

```

Thanks a lot  
Best regards  
Thomas

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [9 September 2020 17:10 UTC](https://discourse.nodered.org/t/help-needed-for-https-post-cookie/32630/6 "2020-09-09T17:10:09Z")

</div>

In case someone finds this topic later on when looking for the same thing, they might be disappointed to find out your code snippet only contains a single debug node. 😉

---

<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:** [23 September 2020 17:10 UTC](https://discourse.nodered.org/t/help-needed-for-https-post-cookie/32630/7 "2020-09-23T17:10:11Z")

</div>

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