question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting 'Cross-Origin Request Blocked' on a GET request

See original GitHub issue

Summary

I’m making a GET request to 4chan’s API for retrieving threads from a board. This is my code:

const board = this.props.routeParams.tag;
var config = {
    headers: {'Access-Control-Allow-Origin': '*'}
};
axios.get('https://a.4cdn.org/' + board + '/threads.json', config)
    .then(function (response) {
        console.log(response.data);
});

I receive the following warning:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://a.4cdn.org/a/threads.json. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). As seen above, I have added the relevant header, but it does not solve the issue. I made the same request from my terminal using cURL and it worked fine.

Context

  • axios version: e.g.: v0.16.0
  • Environment: e.g.: node v6.9.4, Firefox 51.0.1, Ubuntu 14.04

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:111
  • Comments:143

github_iconTop GitHub Comments

479reactions
ronnincommented, Aug 17, 2017

Access-Control-Allow-Origin is a response header, not request header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin

axios.get(url, { headers: {‘Access-Control-Allow-Origin’: *} } ) means nothing!

try axios.get(url, { crossdomain: true })

228reactions
JoseTavarescommented, Jul 17, 2017

Any news on this? I’m pretty much in the same boat…

Read more comments on GitHub >

github_iconTop Results From Across the Web

3 Ways to Fix the CORS Error — and How the Access-Control ...
If the frontend domain does not match the value, the browser raises the red flag and blocks the API request with the CORS...
Read more >
If I get a cross-origin-request-blocked error on my front-end ...
The server then decides whether to allow the request or not. If the browser gets permission from the server, then it sends the...
Read more >
CORS errors - HTTP - MDN Web Docs - Mozilla
If the CORS configuration isn't setup correctly, the browser console will present an error like "Cross-Origin Request Blocked: The Same ...
Read more >
CORS errors and how to solve them - Topcoder
CORS is an abbreviation for Cross-Origin Response Sharing. It is what allows the website on one URL to request data from a different...
Read more >
The Cross-Origin Request Blocked Error - Logi Analytics
Cross -origin resource sharing (CORS) is a new standard introduced in HTML 5 that allows web applications to use HTTP headers to specify...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found