Saturday, 8 April 2017

Retrieve Cookie, store, and use

I'm using npm package 'request' to make API calls. Upon initial login, I should receive a cookie back, I need to store that cookie indefinitely to make subsequent calls.

I'm doing this in Python with requests like so:

#set up the session   
s = requests.session()
#logs in and stores the cookie in session to be used in future calls
request = s.post(url, data)

How do I accomplish this in node? I'm not tied to anything right now, the request package seems easy to work with, except I'm having issues getting known username and passwords to work, that said, I'm sure that's mostly my inexperience with JS/node.js.

This is all backend code, no browsers involved.

I need to essentially run a logon function, store the returned encrypted cookie and use for all subsequent calls against that API. These calls can have any number of parameters so I'm not sure a callback in the logon function would be a good answer, but am toying with that, although that would defeat the purpose of 'logon once, get encrypted cookie, make calls'.

Any advice, direction appreciated on this, but really in need of a way to get the cookie data retrieved/stored for future use.



via Dr. Nefario

No comments:

Post a Comment