所以我部署了一个项目(使用的框架是ReactJS)到Heroku,并且给定的URL使用HTTPS协议(protocol)。我遇到的问题是获取数据的来源使用 HTTP 协议(protocol),因此返回此错误...
Here's is the code responsible for getting the data
import axios from 'axios';
const api = axios.create({
baseURL: 'http://api.decoprim.md/v1/items?key=3VG8BizGax',
});
export function getProducts() {
return api.get().then(response => response.data.data);
}
最佳答案
Cross-Origin Resource Sharing (CORS)正在阻止您的请求,如果页面通过 https 加载,您应该对所有资源使用 https,但如果您不能更改它,您可以使用第三方服务绕过它,例如:
- CORS 无处不在:https://cors-anywhere.herokuapp.com/
- 所有来源:http://allorigins.me/
- 任何来源:http://anyorigin.com/
示例基本 url:
https://allorigins.me/get?url=http%3A//api.decoprim.md/v1/items%3Fkey%3D3VG8BizGax&method=raw
关于reactjs - 从 http 源获取数据到 https 源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49149814/