he value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true'

主宰稳场 提交于 2019-12-11 06:07:54

问题


in my application i'm building a frontend website (build on React) and i use PHP as my backend. I keey getting the error:

jquery.js:9600 Failed to load http://localhost:81/: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. Origin 'http://localhost:3000' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

my PHP headers are:

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');

my frontend request looks like this:

$.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
  });

回答1:


Well you have not specified values for the header "Access-Control-Allow-Headers". The value should be a comma separated list of request headers that are allowed. The header is optional and not required for Cross-Site Origin Requests (CORS). See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers.



来源:https://stackoverflow.com/questions/51366935/he-value-of-the-access-control-allow-credentials-header-in-the-response-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!