search

Home  >  Q&A  >  body text

node.js - 急急急!node request如何获取响应中cookie的值呢?

譬如这个

黄舟黄舟2872 days ago699

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 15:24:42

    var j = request.jar()
    request({url: 'http://www.google.com', jar: j}, function () {
      var cookie_string = j.getCookieString(url); // "key1=value1; key2=value2; ..."
      var cookies = j.getCookies(url);
      // [{key: 'key1', value: 'value1', domain: "www.google.com", ...}, ...]
    })

    reply
    0
  • 黄舟

    黄舟2017-04-17 15:24:42

    Guess you are using the request library? If cookies are set in the response, you can try

    response.headers['Set-Cookie']

    reply
    0
  • Cancelreply