javascript - npm tough-cookie: save a cookie and then dump it -


i want simple task:

  1. make http request (npm install request) http://google.com , save cookie cookiejar
  2. see list of cookies in cookiejar in console verify cookie indeed there
  3. dump cookies cookiejar , sort of confirmation it's done (like console.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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -