![](/img/trans.png)
[英]'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
[英]' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
我已经尝试解决这个问题超过一个星期。 我是新来的流星。 即使我不太懂英语,我也想自己学习。
但我正在尝试访问一个获得此eh encotrado的api,您应该输入如下消息
Access-Control-Allow-Origin: *
但我不知道怎么去哪里
也尝试将{mode: 'no-cors'}
fetch('http://sipla.cuci.udg.mx/sc/horariop.php?c=219359735&k=0d8ce4fab5f4df9ce711cae81e044e1a',{mode: 'no-cors'})
对我没用
componentDidMount() {
fetch('http://sipla.cuci.udg.mx/sc/horariop.php?c=219359735&k=0d8ce4fab5f4df9ce711cae81e044e1a')
.then((response) => {
return response.json()
})
.then((dat) => {
this.setState( {datos1: dat })
})
}
假设您尝试访问该URL时遇到CORS错误; 您可以在URL上添加反向代理CORS前缀,以进行呼叫以绕过该URL;
只需在URL前面加上“ https://cors-anywhere.herokuapp.com/ ”,就不会出现该跨源错误。
var url = 'https://cors-anywhere.herokuapp.com/http://sipla.cuci.udg.mx/sc/horariop.php?c=219359735&k=0d8ce4fab5f4df9ce711cae81e044e1a';
fetch(url, {
method: 'GET',
headers:{
'X-Requested-With': 'XMLHttpRequest'
}
}).then(res => res.json())
.then(response => console.log('Success:', response))
.catch(error => console.error('Error:', error));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.