reactjs - react-redux 桌面应用程序中请求的资源错误中不存在 Access-Control-Allow-Origin' 标头
问题描述
我正在从 API 获取数据,但它没有用。它给了我这样的错误" Access to fetch at 'http://muslimsalat.com/lahore/false/5.json?key=API_KEY' from origin 'http://localhost:3000' has been 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. "
当我在 react-native 移动设备中获取数据时,它可以工作,但是当我在 react 桌面中获取数据时,它无法正常工作。
谁能告诉我这个错误的原因是什么,我该如何解决?
解决方案
将 CORS 添加到 API URL。您只需将本地 IP 添加到后端服务 (API)。如果您需要适当的代码让我们知道您使用哪种语言作为后端 API。
推荐阅读
- mysql - MySQL - 如何通过隐藏行 sub_id 过滤行
- python - Tkinter:你能看到一个小部件的所有绑定吗?
- node.js - 使用 Puppeteer 打印除最后一页之外的所有 pdf 页
- angular - 如何使用对服务上的事件发射器做出反应的订阅进行异步测试?
- python - 什么原因导致“Poly object has no attribute 'expand'”错误?
- c# - 如何转义连接字符串中的空格
- django - Django 使用哪种类型的身份验证系统开箱即用?
- python - 在python中生成具有一定长度的随机字符串行的最快方法
- angular - 如何在ngrx单元测试中更新mockstore中的状态?
- c++ - 尝试访问数组元素时出现分段错误,因为数组值在传递给函数后不会改变