【发布时间】:2022-11-17 21:44:26
【问题描述】:
我想从我的网站向我的后端发送一个 POST 请求。但我收到以下错误:
blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
我的代码
const response = await fetch("http://172.18.6.249:8090/test", {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: `{
"Id": 78912,
"Customer": "Jason Sweet",
"Quantity": 1,
"Price": 18.00
}`,
});
response.json().then(data => {
console.log(data);
});
服务器目前不使用任何类型的身份验证。
我怎样才能避免这个错误?
【问题讨论】:
标签: javascript post fetch-api