简体   繁体   中英

request.js - cookie creation

I'm trying to add a cookie to request.js module (https://github.com/mikeal/request) but I got lost

Does any one have some experience with this ?

The code I've is :

 var j = request.jar();
        var cookie = request.cookie('TENANTID');
        j.setCookie(cookie, 'public');


var requestSettings = {
            method: self.method[m],
            url: url.format({
                    pathname : self.getServer() + u,
                    query: {tenant: (process.env.STORM_DB_TENANTS_NAME || 'public')}
                }),
            headers: {'Content-Type': self.headers[h]},
            jar : true
        };

The question is how do I combine them ?

in you requestSettings you need to assign jar: j instead of jar: true .

So your requestSettings would look like this:

var requestSettings = {
    method: self.method[m],
        url: url.format({
            pathname : self.getServer() + u,
            query: {tenant: (process.env.STORM_DB_TENANTS_NAME || 'public')}
        }),
    headers: {'Content-Type': self.headers[h]},
    jar : j    // The request.jar() object you created and added the cookie to.
};

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