In a browser, if I send a GET request, the request will send the cookie in the meanwhile. Now I want to simulate a GET request from Node, then how to write the code?
相关问题
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- google-drive can't get push notifications
- How to reimport module with ES6 import
- Why is `node.js` dying when called from inside pyt
- How to verify laravel passport api token in node /
相关文章
- node连接远程oracle报错
- How can make folder with Firebase Cloud Functions
- @angular-cli install fails with deprecated request
- node.js modify file data stream?
- How to resolve hostname to an ip address in node j
- Transactionally writing files in Node.js
- Log to node console or debug during webpack build
- Get file created date in node
If you want to do it with the native
http:request()
method, you need to set the appropriateSet-Cookie
headers (see an HTTP reference for what they should look like) in theheaders
member of theoptions
argument; there are no specific methods in the native code for dealing with cookies. Refer to the source code in Mikeal'srequest
library and or thecookieParser
code inconnect
if you need concrete examples.But Femi is almost certainly right: dealing with cookies is full of rather nitpicky details and you're almost always going to be better off using code that's already been written and, more importantly, tested. If you try to reinvent this particular wheel, you're likely to come up with code that seems to work most of the time, but occasionally and unpredicatably fails mysteriously.
Using the marvelous request library cookies are enabled by default. You can send your own like so (taken from the Github page):