cors - 接收到请求的资源上不存在“Access-Control-Allow-Origin”标头,并带有 axios get 请求
问题描述
我正在使用以下请求:
axios.get('https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=43.2502078,13.513169&radius=1500&type=restaurant&keyword=cruise&key=MYKEY',{headers: {'Access-Control-Allow-Origin': '*'}})
.then(response => this.setState({restaurantsFetchedFromGoogle:response.data}));
但我仍然No 'Access-Control-Allow-Origin' header is present on the requested resource
在我的控制台上收到。该 url 工作正常,因为它在使用 Postman 时获取结果。我究竟做错了什么?
解决方案
解决方法npm install cors --save
,移除{headers: {'Access-Control-Allow-Origin': '*'}}
并重新运行本地服务器
推荐阅读
- javascript - 如何获取各种复选框的值
- json - 如何在反应中从 json 文件中读取单个对象?
- authentication - GCP App Engine - 无法加载默认凭据
- r - 如何在 R 中选择最佳的变量组合(NA 更少)
- python - Django 为最新帖子重定向 URL 视图
- swift - Swift保留周期与否
- c# - 如何在 C# 中将 IExtensibleDataObject 存储到列表中
- javascript - 带有 useContext 的 HOC。无效的挂钩调用。Hooks 只能在函数组件的主体内部调用
- python-3.x - Perceptron 函数的基本模型在运行迭代 Python 后没有给出所需的结果
- neo4j - 有没有办法在 GraphDB 中使用 SPARQL 找到两个节点之间的最短路径?