获取请求不向PHP服务器发送cookie

时间:2018-06-12 14:35:50

标签: javascript php fetch-api

我遇到一个奇怪的问题,当我在开发中从客户端发出获取请求时,它不会将cookie发送到我的服务器(不在localhost上运行的旧服务器)。

以下是我的获取请求代码:

get( url ) {
    return fetch(`${API_URL}${url}`, {
      method: 'GET',
      headers: headers(),
      credentials: 'include'
    }).then( parseResponse );
  },

Headers是一个返回以下对象的函数:

{
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'mobile': 'false'
  }

以下是我在服务器上设置的CORS标头(Access-Control-Allow-Origin是动态的,因为fetch与*有问题)

Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: mobile, Content-Type
Access-Control-Allow-Origin: http://localhost:3000

如果我打印出来$_COOKIE我会找回一个空数组,当我查看请求时,我得到Provisional headers are shown没有cookie。

我弄乱了什么想法?

提前致谢: - )

0 个答案:

没有答案
相关问题