![](/img/trans.png)
[英]Access to fetch at 'https://localhost:7144/api/employees' from origin 'http://localhost:3000' has been blocked by CORS policy
[英]Access to fetch at 'https://randomuser.me/api/?results=4' from origin 'http://localhost:3000' has been blocked by CORS policy:
我一直在我的控制台中得到这个,我不明白,请有人帮我解释一下。 Access to fetch at ' https://randomuser.me/api/?results=4 ' from origin ' http://localhost:3000 ' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is出现在请求的资源上。 如果不透明的响应满足您的需求,请将请求的模式设置为“no-cors”以获取禁用 CORS 的资源。
在您的 api 域https://randomuser.me
中,将localhost
添加到允许的来源列表中。
您收到此错误的原因是因为https://randomuser.me
期望来自原点https://randomuser.me
的请求,而不是来自其他来源的请求,例如来自您的localhost
。 如果不满足此要求,浏览器会将其作为警告/错误返回。
为了能够在反应应用程序中允许 API 代理 - 您需要使用以下内容编辑 package.json
"proxy": "https://randomuser.me",
更多细节可以在 create-react-dev 文档中找到
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.