-2

i'm trying to fetch data using axios.

So i init my api like this :

 import axios from 'axios';

export default axios.create({
    method: 'get',
    baseURL: `https://www.data.gouv.fr/fr/datasets/r/a7596877-d7c3-4da6-99c1-2f52d418e881`,
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'Access-Control-Allow-Origin': '*'
    }
});

But i get 'Access to XMLHttpRequest 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.

Any clue on how to resolve this issue ? Thanks

Stéphane Joos
  • 743
  • 1
  • 6
  • 13
  • The server needs to enable CORS for you – Shubham Khatri May 14 '20 at 10:27
  • Does this answer your question? [Why doesn’t Postman get a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error when my JavaScript code does?](https://stackoverflow.com/questions/20035101/why-doesn-t-postman-get-a-no-access-control-allow-origin-header-is-present-on) – Ajeet Shah May 14 '20 at 10:27

1 Answers1

0

If you have any experience with node or access to your apps backend you can simply write an endpoint to consume the api and then forward to you.

There are some more interesting options here: https://github.com/axios/axios/issues/853

Can't comment because of rep.