how to get cookies from https server and save them

I'm studying node.js and trying to implement the following task:

  1. I have to get connection to existing https - for this purpose I decided to choose needle module:

    needle.post('https://...', data, options, function (err, res, body){ });
    
  2. I need to send a request to server as json object using these parameters:

    {"action": "AuthenticationManagement", "method":"login", "data": [null, null], "type": "rpc", "tid": 1}
    

    As I understand it, these parameters should be sent in terms of data within needle.post.

  3. In case I have connected to the server, I need to get cookies from it (sessionID parameter, etc) and save it to file/keep it in memory during my further operations with server. Looks like, cookies should be sent back in res.headers.

  4. Properly end the session.

Any help will be much appreciated.

Needle does not support cookies yet. I 'd suggest using a different library rather than rolling your own implementation over needle.