Jose Martin Lopez
Jose Martin Lopez

Reputation: 75

' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource

I've tried to solve this problem for more than a week. I'm new to this meteor. I'm trying to learn by myself even because I do not know English very well.
but I'm trying to access an api that I get this eh encotrado that you should put a message like

Access-Control-Allow-Origin: *

but I do not know how and where

also try to put {mode: 'no-cors'}

fetch('http://sipla.cuci.udg.mx/sc/horariop.php?c=219359735&k=0d8ce4fab5f4df9ce711cae81e044e1a',{mode: 'no-cors'}) no work for me

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 })
        })    
    }

Upvotes: 7

Views: 28812

Answers (1)

Ilan P
Ilan P

Reputation: 1792

Assuming you're getting a CORS error when trying to hit that URL; you can add reverse-proxy CORS prefix to the URL to make your call to bypass it;

Just prepend 'https://cors-anywhere.herokuapp.com/' to the URL and you shouldn't get that cross origin error;

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));

Upvotes: 11

Related Questions