响应中 'Access-Control-Allow-Credentials' 标头的值是必须'true'



在我的应用程序中,我正在构建一个前端网站(基于React构建(,并使用PHP作为后端。我一直在得到错误:

jquery.js:9600加载失败http://localhost:81/:的值响应中的"Access Control Allow Credentials"标头为"当请求的凭据模式为"include"时,必须为"true"。原点'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
});

您还没有为标头"Access Control Allow Headers"指定值。该值应该是允许的请求标头的逗号分隔列表。标头是可选的,对于跨站点原始请求(CORS(来说不是必需的。请参阅:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers.

相关内容

最新更新