【发布时间】:2022-01-01 17:21:19
【问题描述】:
我在 Ubuntu 上使用 Vapor 作为后端,使用 Next.js 作为前端,并希望以这种方式访问数据库:
let cq = {
text: "My question",
};
axios({
method: "post",
url: `http://localhost:8080/createQuestion`,
data: cq,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "http://localhost:3000",
},
}).catch((err) => console.error(err));
我收到了这样的回复: 从源“http://localhost:3000”访问“http://localhost:8080/createQuestion”的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:没有“访问控制” -Allow-Origin' 标头存在于请求的资源上。
怎么会这样
"Access-Control-Allow-Origin": "http://localhost:3000"
存在于代码中,我收到了上一条错误消息。 我什至尝试过“Access-Control-Allow-Origin”:“*”,但没有帮助。
【问题讨论】: