How to solve 'Redirect has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header'?
Solution 1
In addition to what awd mentioned about getting the person responsible for the server to reconfigure (an impractical solution for local development) I use a change-origin chrome plugin like this:
You can make your local dev server (ex: localhost:8080)
to appear to be coming from 172.16.1.157:8002 or any other domain
.
Solution 2
Thanks all, I solved by this extension on chrome.
Allow CORS: Access-Control-Allow-Origin
Solution 3
If you have control over your server, you can use PHP:
<?PHP
header('Access-Control-Allow-Origin: *');
?>
Solution 4
Ask the person maintaining the server at http://172.16.1.157:8002/ to add your hostname to Access-Control-Allow-Origin hosts, the server should return a header similar to the following with the response-
Access-Control-Allow-Origin: yourhostname:port
Solution 5
When you have this problem with Chrome, you don't need an Extension.
Start Chrome from the Console:
chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security
Maybe you have to close all Tabs in Chrome and restart it.
Parkar
Updated on July 08, 2022Comments
-
Parkar almost 2 years
I am working on an app using
Vue js
. According to my setting I need to pass to a variable to my URL when setting change.<!-- language: lang-js --> $.get('http://172.16.1.157:8002/firstcolumn/' + c1v + '/' + c1b, function (data) { // some code... });
But when my app hit on URL, it shows the following message.
Failed to load http://172.16.1.157:8002/firstcolumn/2017-03-01/2017-10-26: Redirect from 'http://172.16.1.157:8002/firstcolumn/2017-03-01/2017-10-26' to 'http://172.16.1.157:8002/firstcolumn/2017-03-01/2017-10-26/' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
-
user5014677 over 6 years@RoryMcCrossan it says origin is localhost, so cors get triggered. I think?
-
Black about 6 yearsIm not sure how to set it up, can you explain further? Screenshots would be nice.
-
tw1742 over 5 years@altShiftDev Does this plugin have any options to handle: "Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request."?
-
kabrice over 4 yearsThe link is now broken :(
-
Cyber over 4 yearsbroken link, no description at all.
-
Cyber over 4 yearsadded into my
.htaccess
of local project and works like charm, don't forget to reboot your server / mamp / apache, whatever you use. -
Cyber over 4 yearsbetter add to the .htaccess file, this would apply to the entire project and not just to the sites you have added this snippet.
-
ewalel over 4 yearsThanks this helps to avoid all the hassle and test the code from localhost.
-
Peter VARGA over 4 yearsUpdate the link my friend!
-
Jordan Noel over 4 years
-
OM Bharatiya over 4 yearsHey, the chrome extension link provided is broken. Can you please update the answer?
-
SJX about 4 yearsYou don't need an Extension for Chrome: stackoverflow.com/a/60950835/2280067
-
Nitin Nanda over 3 yearsthe extension is just a temporary fix and not a solution to the problem
-
MeVR about 3 yearsmay i know how to solve this from angular side?
-
andromeda about 3 yearsThis is not a solution. Are you going to ask everyone to install a chrome extension?
-
Mike Q about 3 yearsThis didn't seem to work for me, it broke the API call actually.
-
Lepy about 3 yearsTry to put your real ip instead of the localhost. Try to google your ip and replace 'localhost' with that @Black
-
Jagadish Nallappa almost 3 yearsThank you so much! This worked... Cheerio!
-
Darius.V over 2 yearsfor me it does not even reach php script
-
Kasyful Anwar over 2 yearsThis is an extension for Chrome
-
Arslan Ahmad khan over 2 yearsgreat suggetion
-
Dogunbound hounds over 2 yearsDoesn't work buddy.
-
Vixxd over 2 yearsA word of warning: the Moesif Origin & CORS Changer plug-in requires you enter a work-related e-mail address to access the advanced settings. I would not recommend.
-
Pankaj Kumar almost 2 yearsThanks,Thanks .... It solved my headache.