浏览器不会发送已存储的Cookie

时间:2018-11-15 10:30:18

标签: javascript cookies axios

以下是我根据登录请求从服务器后端发送的响应标头。服务器在localhost:8090上运行,我正在使用react-scripts从localhost:3000服务该站点。 Chrome和Firefox都存储“站点” http://localhost:3000的cookie。我正在使用axios发送API请求,如下所示。问题在于后续的api请求不会发送cookie。通过搜索,我认为该端口不起作用,所以问题是为什么未设置cookie?

HTTP/1.1 200 OK
Vary: Origin
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://localhost:3000
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Content-Type: application/json
Content-Length: 42
Set-Cookie: appcredentials=gXXXXXBb7GukifOC_xoQrQAEilZ6MlKa2IbNAPo9HIiIvw97qCpqUnBPfcdBp-o4eZVAXkCPVNfCFMFTlr-mi5-Ie9FkCg3BO-PGw-3sfDL3dPKA66vNNevK9089C7DCkBMwYpEcz3dm5HVcHVTXQVRk9M2oBNrDzXhczfhJFI_gubdYDt2BKjRCx6bRUkfgPEV_N-VyKmbR; Domain=localhost; Path=/
userId="gh@gh.com"; expires=Wed, 28 Nov 2018 18:38:06 GMT; Path=/
Date: Wed, 14 Nov 2018 18:35:36 GMT
Server: Python/3.5 aiohttp/2.2.5

axios呼叫:

export const get_features = (callback) => async dispatch => {
  console.log('get the features man', cookie.load('appcredentials'))
  try {
    const response = await axios.get(
      'http://localhost:8090/app/features',
      null,
      {withCredentials:true}
    );
    dispatch({ type: GET_FEATURES, payload: response.data });
    callback();
  } catch (e) {
    dispatch({ type: AUTH_ERROR, payload: e });
  }
};

顺便说一句,console.log正确记录了cookie的值。

0 个答案:

没有答案