1

I'm trying to use node.js request to fetch a page from a webserver we use. I retrieve the cookies from the results of the previous request, and now trying send them to the profile page as request argument.

var request = require('request'),
fileCookieStore = require('tough-cookie-filestore');

var j = request.jar(new fileCookieStore("./cookie.json"));
var options = {
    url     : 'http://example.com/site/page.php?u=1234',
    jar     : j,
    headers : {
        "User-Agent":"user_agent"
    }
};

request(options, function(err,res,body) {
if(err){
    console.log(err);
    return;
    }
console.log('body');
});

cookie file looks like that:

[{
    "domain": "www.example.com",
    "expirationDate": 1482144640.897115,
    "hostOnly": true,
    "httpOnly": true,
    "name": "password",
    "path": "/",
    "secure": false,
    "session": false,
    "storeId": "0",
    "value": "8ff31b0edcf85b72b20469044dafc373",
    "id": 1
  },
  {
    "domain": "www.example.com",
    "hostOnly": true,
    "httpOnly": true,
    "name": "sessionhash",
    "path": "/",
    "secure": false,
    "session": true,
    "storeId": "0",
    "value": "13d0e4ff1bdeefbe118df4ad04c81a2e",
    "id": 2
  }]

and there's no luck. body in console log says that I'm still not logged in. How can I do that?

3
  • What if the session stored in the cookie is expired? Commented Dec 20, 2015 at 19:40
  • You could use Fiddler to capture network traffic and debug Commented Dec 20, 2015 at 19:41
  • @hege_hegedus - this helps a bit : var j = request.jar(); j.setCookie(request.cookie('key1=value1','key2=value2'); but only for first login. For the first time it log me in succesfully, the second attempt in a five second fails, I am not logged again. Something wrong with cookies, I think. Sadness. Commented Dec 20, 2015 at 21:00

1 Answer 1

1

Try to pass j object, the one that you passed in jar method in your next request. I do something similar at my work

from request website:

jar - If true, remember cookies for future use (or define your custom cookie jar; see examples section)

https://github.com/request/request

Sign up to request clarification or add additional context in comments.

1 Comment

thanx, I'll try to do this soon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.