问题
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