使用node.js请求模块获取FileCookieStore的页面

我正在尝试使用node.js请求从我们使用的networking服务器获取页面。 我从前一个请求的结果中获取cookie,现在尝试将它们作为请求参数发送到configuration文件页面。

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文件看起来像这样:

 [{ "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 }] 

没有运气。 控制台日志中的主体说,我还没有login。我该怎么做?

尝试传递j对象,您在下一个请求中通过jar方法传递的对象。 我在工作上做了类似的事情

从请求网站:

jar – 如果是true,则记住cookie以备将来使用(或定义自定义cookie jar;请参阅示例部分)

https://github.com/request/request