2

I try to make a simple GET call with axios.

Lets say I have the following code:

import axios from 'axios'
axios.get('https://www.wikipedia.org/')

The browser (Firefox) logs the following error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.wikipedia.org/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

In the Developer Toolbar - Network there is the right response.

When I copy the request as cURL and past it in the console it works.

Is this a problem with axios, firefox or wikipedia.org?

How do I fix this problem?

Piu130
  • 1,288
  • 3
  • 16
  • 28
  • Possible duplicate of [CORS error while making axios.get call](https://stackoverflow.com/questions/35164116/cors-error-while-making-axios-get-call) – Obsidian Age Jan 18 '18 at 21:03
  • But why is this a server problem? cURL works, and also direct call to the url works... – Piu130 Jan 18 '18 at 21:24
  • 1
    `axios` is an AJAX request, while CURL is a `server` request. In simpler words, CURL is a separate browser, while axios is your server. Since you don't own the wikipedia server, you cannot really access Wikipedia's server items from your server asynchronously using XMLHttpRequest – Dhiraj Jan 18 '18 at 21:30
  • It’s unclear from you question what actual data you’re really trying to get from Wikipedia. But if what you’re really do is trying to use the Wikipedia *API*, then see the answer at https://stackoverflow.com/questions/47733007/cors-header-access-control-allow-origin-missing-from-wikipedia-api-response/47733422#47733422. The gist of it is, you need to add `origin=*` to the query string. – sideshowbarker Jan 19 '18 at 01:41

1 Answers1

0

According to this comment, AJAX is limited by the same origin policy while cURL is not.

Thats what was not clear from CORS error while making axios.get call. It was just a solution for the problem with no explanation.

Thanks for the comments. If you are interested in access wikipedia see zuifs comment.

Piu130
  • 1,288
  • 3
  • 16
  • 28