【问题标题】:he value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true'响应中“Access-Control-Allow-Credentials”标头的值为“”,必须为“真”
【发布时间】:2018-12-24 07:16:16
【问题描述】:

在我的应用程序中,我正在构建一个前端网站(基于 React),并且我使用 PHP 作为我的后端。 我不断收到错误消息:

jquery.js:9600 加载失败http://localhost:81/: 的值 响应中的“Access-Control-Allow-Credentials”标头是“” 当请求的凭据模式为“包含”时,必须为“真”。 因此,Origin 'http://localhost:3000' 不允许访问。这 XMLHttpRequest 发起的请求的凭证模式是 由 withCredentials 属性控制。

我的 PHP 标头是:

header('Access-Control-Allow-Origin: http://localhost:3000'); 
// header("Access-Control-Allow-Origin: *"); 
header('Content-Type: application/json');
header('Access-Control-Allow-Headers');
header('Access-Contol-Allow-Credentials: true');

我的前端请求如下所示:

$.post(
    {
      async: false,

      type: "POST",
      url:'http://localhost:81',
      data: 
      {
        querytype: "dataRequest"
      },
      crossDomain : true,
      xhrFields: {
          withCredentials: true
      },
      complete: this.completed,
      success: this.reqsuccess,
      error: this.reqError
  });

【问题讨论】:

    标签: php header cors packets


    【解决方案1】:

    您还没有为标题“Access-Control-Allow-Headers”指定值。该值应该是允许的请求标头的逗号分隔列表。标头是可选的,跨站点源请求 (CORS) 不需要。请参阅:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers

    【讨论】:

      猜你喜欢
      • 2019-02-08
      • 2017-10-02
      • 2021-04-04
      • 2018-01-13
      • 2021-04-17
      • 2015-04-14
      • 2021-03-12
      • 2022-11-28
      相关资源
      最近更新 更多