how to using cookie with request (request , tough-cookie , node.js)
I just found the solution ....
theJar.setCookie('test=1234; path=/; domain=examples.com', 'http://examples.com/');
hm...I have to say, the document which for request is not so good..., lol
PatrickSCLin
Updated on June 14, 2022Comments
-
PatrickSCLin about 2 years
I'm wondering to know how to using cookie with request (https://github.com/mikeal/request)
I need to set a cookie which able to be fetched for every sub domains from request,
something like
*.examples.com
and the path is for every page, something like
/
then server-side able to fetch the data from cookie correctly, something like
test=1234
I found the cookies which setup from response was working fine,
I added a custom jar to save the cookies, something like
var theJar = request.jar(); var theRequest = request.defaults({ headers: { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36' } , jar: theJar });
but the cookies which I setup from request, only able to be fetched in same domain,
and I can't find a method to setup cookie in more options
for now if I want one cookie which able to be fetched in three sub domains,
I have to setup like this way:
theJar.setCookie('test=1234', 'http://www.examples.com/', {"ignoreError":true}); theJar.setCookie('test=1234', 'http://member.examples.com/', {"ignoreError":true}); theJar.setCookie('test=1234', 'http://api.examples.com/', {"ignoreError":true});
Is here any advance ways to setup a cookie from request,
made it able to be fetched in every sub domains ???
-
Nicolas S.Xu almost 10 yearsI am making http request to localhost, but cookie is not carried along requests. how do I make sure cookie is carried in the header using request with jar: true?
-
Michael over 7 yearssetCookie seems really wonky... it doesn't autodetect "secure", it doesn't set the domain from the URL i passed, and using "ignoreError" results in the callback never being called.