简体   繁体   中英

How to prevent session from external site from timing out?

I am using nodeJS to create an application to create simplified experience of our college's student portal which uses session based authentication. I am aware that in python, we have requests module, from which, we can use requests.Session() object to make get, post etc. requests from the same session. What is the NodeJS equivalent of this?

Also, the portal is set to end the session after 15 mins of inactivity. Is there something I can do to avoid this ie generate a never ending session?

Got the solution for this. I used axios to make requests.

const axios = require("axios");
const axiosCookieJarSupport = require("axios-cookiejar-support").default;
const tough = require("tough-cookie");
axiosCookieJarSupport(axios);
const cookieJar = new tough.CookieJar();
axios.get(url, {
    jar: cookieJar,
    withCredentials: true,
  }).then((res)=>{
    //do your stuff
    //any set-cookie headers will be automatically processed.
    //use the same config for further requests, 
    //it will automatically send the cookies alongside the requests.
  })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM