In nodejs how to send cookies in a request to a server

user1868405 picture user1868405 · Aug 14, 2013 · Viewed 8.8k times · Source

how can we receive a cookie as the 'set-cookie' parameter of the response and header and then send this cookie in next request.All this using the 'http' module and no 3rd party modules.I am basically interested on how i will post the cookie as a parameter in the header about to go in the next request

Answer

user1868405 picture user1868405 · Aug 18, 2013

oh finally found my mistake i wasnt including the cookie parameter in my header list.I was writing it like this:

var options = {host:url_parsed.host, path:url_parsed.path, method:'GET', 'Cookie':cookie, 'Accept':'/', 'Connection':'keep-alive', };

I should actually be like this:

 var options = {host:url_parsed.host, path:url_parsed.path, method:'GET', headers:{'Cookie':cookie}, 'Accept':'/', 'Connection':'keep-alive', };