# Node-Red HTTP Request and session cookies

**URL:** https://discourse.nodered.org/t/node-red-http-request-and-session-cookies/6236
**Category:** General
**Created:** [30 December 2018 17:39 UTC](https://discourse.nodered.org/t/node-red-http-request-and-session-cookies/6236 "2018-12-30T17:39:50Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![masterz666](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@masterz666](https://discourse.nodered.org/u/masterz666)
#### Post date: [30 December 2018 17:39 UTC](https://discourse.nodered.org/t/node-red-http-request-and-session-cookies/6236/1 "2018-12-30T17:39:50Z")

</div>

Hi,

I'm trying to control my alarm system (Somfy protexiom 800) from Node-Red.  
My starting point was a shell script by jcjames\_13009 (located here: [[Bash] Script alarme Somfy Protexiom 5000 - Forum Domoticz en français](https://easydomoticz.com/forum/viewtopic.php?t=2831)) which mainly uses curl.

I recreated the login part in Node-Red, my login is successful and I'm getting a session cookie which is used as authentication for the rest of the session.  
It originally comes in "msg.responseCookies" and looks like this:  
`{"sid":{"path":"/","value":"1234"}}`

Whenever I try to access the interface of the alarm system, I always get an error page saying 'there's already a session open, try again later'.

I know that my session cookie is OK because:

- I can reuse it from firefox by editing the cookie manually, using the sessionID received in Node-Red.  
The firefox cookie looks like this:

> ```
> {
> "name": "sid",
> "value": "1234",
> "domain": "myalarm",
> "hostOnly": true,
> "path": "/",
> "secure": false,
> "httpOnly": true,
> "sameSite": "no_restriction",
> "session": true,
> "firstPartyDomain": "",
> "storeId": "firefox-default",
> "origin": "http://myalarm"
> }
> 
> ```

- I'm also able to get into the session from another PC, using curl and a forged cookie file, again reusing the same sessionID:  
The curl cookie file looks like this:

> ```
> # Netscape HTTP Cookie File
> # https://curl.haxx.se/docs/http-cookies.html
> # This file was generated by libcurl! Edit at your own risk.
> 
> myalarm FALSE / FALSE 0 sid 1234
> 
> ```

I can't understand why those 2 methods work fine and I can't manage it in Node-Red.

Here's the data I tried passing from a **function** node to an **http request** node (GET):

```auto
var sid_cookie = {"sid":{"path":"/","value":"1234"}}
msg.cookies = {sid_cookie};

```

```auto
> msg.headers = {};
> msg.headers["cookie"] = sid_cookie;

```

```auto
> msg.cookies = "sid=" + sid_cookie.sid.value

```

then I tried using similar headers as what curl is sending:

```auto
> msg.headers = {};
> msg.headers["cookie"] = "sid=" + sid_cookie.sid.value;
> msg.headers["Accept"] = "*/*";
> msg.headers["User-Agent"] = "curl/7.58.0";
> msg.headers["host"] = "myalarm";
> msg.headers["Referer"] = "http://myalarm" ; //also tried this
> msg.headers["connection"] = "close"; //also tried this because curl send it
> 
> msg.cookies = "sid=" + sid_cookie.sid.value

```

None of those work, although the cookie is passed properly as far as I can see.  
but there must be a difference between the firefox / curl and Node-Red protocol

Thinking that I'm missing some context information, I redirected my curl **http request** , as well as my Node-Red **http request** node to an ' **http in**' node to view both outputs, but I can't see any meaningful differences... (msgid, and header["host"] values)

Has anyone have an idea on how to to this properly, or at least how to troubleshoot this kind of issue ?

---

<div class="post-metadata">

### Author: ![masterz666](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@masterz666](https://discourse.nodered.org/u/masterz666)
#### Post date: [31 December 2018 13:58 UTC](https://discourse.nodered.org/t/node-red-http-request-and-session-cookies/6236/2 "2018-12-31T13:58:41Z")

</div>

Ok, I figured it out,

When using msg.cookie or any variation of this, the msg property 'cookie' is always set to lowercase.  
I tried forcing it uppcase but it goes back to lowercase when the message is generated.

So all my subsequent tries using headers were made with 'cookie' as well, as I thought it did not matter.

I used tcpdump to track any differences between the network traffic generated by curl and Node-Red and the only difference was that curl did send the 'Cookie' parameter with an uppercase 'C'.

So I used the following notation in Node-Red:

```
msg.headers = {
    Cookie : "sid=" + sid_cookie.sid.value,
    Accept : "*/*",
    "User-Agent" : "curl/7.58.0",
    Host : "alarmesomfy",
    connection : "close"
}

```

And that did the trick.

---

<div class="post-metadata">

### Author: ![Hitman2847](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hitman2847/32/68588_2.png) [@Hitman2847](https://discourse.nodered.org/u/Hitman2847)
#### Post date: [30 October 2022 05:44 UTC](https://discourse.nodered.org/t/node-red-http-request-and-session-cookies/6236/3 "2022-10-30T05:44:34Z")

</div>

a little late to the party but I am fairly new to this and had a problem, I am implementing a login page, so I am setting cookies in the browser, now the problem is I can change the cookie but I can't edit one property of the cookie (and I don't want to resubmit the same cookie so the expiration time would not be changed as a result)

I used this example to submit my cookie: [[Work with cookies : Node-RED](https://cookbook.nodered.org/http/work-with-cookies)], I did change it though as I wanted to store more data, like the time the cookie was submitted, sessionID, token, and the username.  
I set each of these as a separate object inside the cookie and each one have multiple properties. I don't know any other methods to edit the existing cookie in node-red and by using the clear cookie method here I can't set only one value to null.  
I would appreciate any help.  
here is how my cookie the way I set it:

---

<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: [30 October 2022 07:41 UTC](https://discourse.nodered.org/t/node-red-http-request-and-session-cookies/6236/4 "2022-10-30T07:41:44Z")

</div>

> [@Hitman2847](#):
>
> a little late to the party

An understatement to say the least 😂

A lot has changed in 4 years.

I am going to close this thread & ask that you start your own. If you provide the right details (actual detail, not just a description of your problem) & if possible, a minimal flow that demonstrates your problem, I'm certain someone will help.

---

<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: [30 October 2022 07:41 UTC](https://discourse.nodered.org/t/node-red-http-request-and-session-cookies/6236/5 "2022-10-30T07:41:49Z")

</div>


