【问题标题】:Making successful requests but cookies are not being set发出成功的请求,但未设置 cookie
【发布时间】:2016-06-05 20:50:42
【问题描述】:

当我使用 Postman(一种 api 服务)向服务器发出请求时,chrome 会自动创建一个 cookie。但是,当我向我的 nodejs 服务器发出请求时,即使请求成功,也不会发出 cookie。

  //Headers
  var options = {
  method: 'GET'
  };
  options.headers = {};
  options.headers.Authorization = auth;
  options.url = urlm;
  console.log(options);

  request(options, function(error,response,body) {

    res.status(200).send(response.headers);
  });

响应头是

{"date":"2016 年 2 月 23 日星期二 20:06:57 GMT","server":"Jetty(9.2.1.v20140609)","x-csrf-header":"X-CSRF- TOKEN","expires":"Thu, 01 Jan 1970 00:00:00 GMT","x-csrf-token":"xxxxxxxxxxx","cache-control":"no-store","content-type" :"audio/mpeg","set-cookie":["JSESSIONID=uiqwnksadbohqjkq675d;Path=/;HttpOnly"],"connection":"close","transfer-encoding":"chunked"}

【问题讨论】:

    标签: node.js cookies


    【解决方案1】:

    在您的请求选项中传递 { jar: true }

    来自documentation

    jar - 如果为真,请记住 cookie 以备将来使用(或定义您的自定义 cookie jar;请参阅 examples section

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-19
      • 2020-06-18
      • 2015-12-21
      • 2020-12-16
      相关资源
      最近更新 更多