使用POST请求登录时,读取服务器发送的cookie

时间:2016-03-16 14:07:12

标签: javascript angularjs post cookies setcookie

我正在进行登录的POST请求,当登录服务器时发送标题" Set-Cookie" 我必须得到它并把它放在浏览器中。我尝试了所有那些没有用过的方法

$.ajax(settings).done(function (data, status, headers, config) {
    console.log(data);
    //$cookies['Set-Cookie']=response.headers('Set-Cookie');
    //console.log(headers);
    //console.log(headears()['Set-Cookie']);
    //console.log(headears(['Set-Cookie']));
    console.log(headers.getResponseHeaders()['Set-Cookie']);
});

console.log(headers);打印"成功"在控制台和其他人我得到" undefined"或者"标题不是函数"。有人可以帮助我。我尝试了我在论坛中看到的所有方法都没有用过。谢谢。

我最近尝试使用此console.log( $cookies.get('xxx'));,但问题是$cookies.get()仅在Cookie已经存储在浏览器中时才有效。我想从printscreent的标题中获取它们并添加他们是手动使用$cookies.put('myfav','oo');谢谢。Response Headers

1 个答案:

答案 0 :(得分:1)

您需要阅读Set-Cookie创建的实际Cookie。

尝试

console.log( $cookies.get('CookieName'));

另请注意,如果它是httpOnly Cookie,您将无法访问它。跨域请求也是如此

相关问题