Hi all,
I'm struggling a bit to create an http flow in node-red... I've been fighting for some days, going ahead, but not achieving the final result, so any help will be a lot
This is tied to this issue, but now closed.
I'm trying to fetch info from a web server which login is controlled by a cookie parameter set as http header, as usual.
When loading the login page the server sends a "set-cokie" parameter in the response headers. I'd need to reuse that parameter which comes in this form:
set-cookie: ASPSESSIONIDCUSRARBR=OLJCEELALEKFHOJOCEEEKAHH; secure; path=/
I'd need to reuse that cookie value (removing the last part I guess) to make requests adding in headers of the http request in this format (this is the example from curl command):
-H 'cookie: ASPSESSIONIDCUSRARBR=OLJCEELALEKFHOJOCEEEKAHH'
I tried several ways, some cleaner than others... but non worked
Some of the ideas... first one was to try to use it directly:
Other idea has been (as I usually inject headers in HTPP requests in node-red) with a change node... and for this i was trying to change msg.headers with "'cookie: " & $msg.headers["set-cookie"][0] & "'"
... but it doesnt come with the cookie value in the middle of the sentence...
Last idea Im trying is with a function...
msg.headers = msg.headers || {};
msg.headers["cookie"] = msg.headers["set-cookie"]
delete msg.payload
let avcookie = ""
let newMsg = {} // clean new msg
// filter cookies from previous reply
msg.headers["cookie"].forEach(el => {
if (el.startsWith("ASPSESSIONID")) avcookie = el.split(";")[0]
})
newMsg.headers = {
"Cookie": `${avcookie}`,
}
//delete msg.headers["set-cookie"]
return newMsg;
And then with a change nod using newMsg as msg.headers...
But non of them worked, all the ideas come from other msgs and forums... thats why some are better/cleaner than others.
I'd like to use the more simple option that exists... if it can be without a function and reusing that set-cookie value somehow... that would be the best
I'm suspecting that my issue is there in the cookie thing... but there is other part of the login request sent in the initial POST (after getting the set-cookie in a previous GET), when doing all of this manually is like:
-H 'cookie: ASPSESSIONIDCUSRARBR=OLJCEELALEKFHOJOCEEEKAHH \
--data-raw 'nic=EMAIL&pwd=PASSWORD&Enviar=Entrar+%2F+Enter'
This part im adding it as msg.payload with a change node injected in login page. As an string, without the simple quotes. Maybe all the headers cookie was right in some if the tries and the issue was here now that im thinking xD, I hope not!
Thanks!