I’ve got a node.js Connect server that checks the request’s cookies. To test it within node, I need a way to write a client request and attach a cookie to it. I understand that HTTP Requests have the ‘cookie’ header for this, but I’m not sure how to set it and send — I also need to send POST data in the same request, so I’m currently using danwrong’s restler module, but it doesn’t seem to let me add that header.
Any suggestions on how I can make a request to the server with both a hard-coded cookie and POST data?
This answer is deprecated, please see @ankitjaininfo’s answer below for a more modern solution
Here’s how I think you make a POST request with data and a cookie using just the node http library. This example is posting JSON, set your content-type and content-length accordingly if you post different data.
What you send in the
Cookievalue should really depend on what you received from the server. Wikipedia’s write-up of this stuff is pretty good: http://en.wikipedia.org/wiki/HTTP_cookie#Cookie_attributes