浏览器未在获取请求后从响应头设置Cookie

时间:2017-06-07 05:54:13

标签: javascript reactjs http-post fetch-api

尝试实现登录页面的获取请求,但不是浏览器未设置从响应中收到的cookie

login(user, pass) {
    console.log("from login=", user)
    var data = { "username": user, "password": pass };
    var url = '***************************************';
    //console.log(data)
    return fetch(url, {
        method: "POST",
        body: JSON.stringify(data), //just pass the instance
        crossDomain: true,
        credentials: 'same-origin'
    }).then((res) => { var head = res.headers; console.log("Headeers", head.get("Cookie")); return res.json(); });
}

chrome dev工具中的Request标头是

Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:57
content-type:text/plain;charset=UTF-8
Host:www.buynsta.com
Origin:http://localhost:3000
Referer:http://localhost:3000/login
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/56.0.2924.87 Safari/537.36

chrome dev工具中的响应标头

Access-Control-Allow-Origin:*
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-              check=0
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:261
Content-Type:text/html; charset=UTF-8
Date:Wed, 07 Jun 2017 05:37:25 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=100
Pragma:no-cache
Server:Apache
Set-Cookie:frontend=ajtcpi320jis092dkv75abllq0; expires=Sat, 17-Jun-2017 05:37:26 GMT; Max-Age=864000; path=/; domain=www.buynsta.com
Set-Cookie:persistent_shopping_cart=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; domain=www.buynsta.com
Vary:Accept-Encoding
X-Frame-Options:SAMEORIGIN
X-Powered-By:PHP/5.6.24

0 个答案:

没有答案
相关问题