javascript - npm tough-cookie: save a cookie and then dump it -
i want simple task:
- make http
request
(npm install request
)http://google.com
, save cookiecookiejar
- see list of cookies in
cookiejar
in console verify cookie indeed there - dump cookies
cookiejar
, sort of confirmation it's done (likeconsole.log('no errors')
)
having gone through docs tough-cookie, i'm having trouble steps 2 , 3, in 2 shows empty array , 3 throws out typeerror: undefined not function
my code below:
//npm install request var request = require('request'); //special request puts cookies in cookiejar var cookierequest = request.defaults( { jar : cookiejar } ) //npm install tough-cookie var tough = require('tough-cookie'); //request store api var store = tough.store var cookie = tough.cookie; var cookiejar = new tough.cookiejar(); //load google.com, assume google set cookies in cookiejar cookierequest("http://google.com",function(error, response, body){ if (!error && response.statuscode==200){ console.log("requestdone") } }); //request see cookies in cookiejar - @ moment it's returning empty array, //would have expected ['cookie' : data ] cookiejar.getcookies("http://google.com",function(err,cookies){ console.log(cookies) }); //here want dump whatever cookies stored in cookiejar - @ moment //throwing 'typeerror: undefined not function' , can't figure out why cookiejar.store.removecookies("http://google.com",function(err){ console.log(err) });
also fyi docs npm-request
Comments
Post a Comment