使用:
async function APIsignUp(name, pass) {
let response = await fetch(domain + `signup`, {
method: "GET",
credentials: "include",
});
return await response.json();
}
它工作得很好,但在添加一些自定义标题后:
async function APIsignUp(name, pass) {
let response = await fetch(domain + `signup`, {
method: "GET",
credentials: "include",
headers: {
"X-Username": name,
"X-Password": pass,
},
});
return await response.json();
}
会抛出错误:
当请求的凭据模式为'include'时,响应中的'Access-Control-Allow-Origin'头的值不能是通配符'*'。
但是我已经在服务器端添加了Access-Control-Allow-Origin, Access-Control-Allow-Credentials和Access-Control-Allow-Headers头(我使用sqark java)
在服务器端:
res.header("Access-Control-Allow-Origin", domain);
res.header("Access-Control-Allow-Credentials", "true");
res.header("Access-Control-Allow-Headers", "X-Username, X-Password");
您可以使用cors包,它将删除疼痛或手动您可以在您的代码中添加原点