你好,我环顾四周,尝试了几件事,无法正常工作。
我有此提取请求:
index = () => {
return fetch(`${baseUrl}api/deliveries`, {
method: 'GET',
headers: new Headers({
'Access-Control-Allow-Origin': 'http://localhost:3000',
'Content-Type': 'application/json',
}),
})
.then(res => res.json());
}
我在控制台中遇到此错误:
Failed to load http://localhost:8000/api/deliveries: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 404. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
错误状态'Access-Control-Allow-Origin'
不存在。但它是。它在那里。
有什么想法?
您不需要发送此标头,需要在服务器的响应中存在。
它应该在服务器上的选项请求的响应中,如错误消息所说。