Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable CORS with wamp on windows 8

I have a cross domain request problem with an application I'm doing. I really spent hours looking for a solution on how to enable CORS with wamp (localhost) but nothing worked for me.

I have Apache 2.4.9 on Windows 8.1. I have enable the headers, I tried to put

Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"

in a .htaccess and in the http.conf as well as countless other variations.

If anyone had a solution that'd be awesome!

like image 682
Simon Avatar asked Nov 21 '14 09:11

Simon


People also ask

How do I enable CORS access?

Simply activate the add-on and perform the request. CORS or Cross-Origin Resource Sharing is blocked in modern browsers by default (in JavaScript APIs). Installing this add-on will allow you to unblock this feature.

Is CORS enabled by default?

CORS is off by default for security purposes.

How do I enable CORS in hosting?

The easiest way to enable CORS is to speak to your website host directly. If you're new to site management, it may seem tedious to manually enable CORS on your website. In this case, it's best to get in touch with a technical support representative and ask them to enable CORS for your website.


2 Answers

You must also activate the Apache Headers module.

Using the wampmanager menus do this :-

wampmanager -> Apache -> Apache modules -> headers_module

Make sure this is ticked, if its not, click that menu item and wait a few seconds while WampServer restarts Apache.

like image 131
RiggsFolly Avatar answered Sep 20 '22 12:09

RiggsFolly


I had the same problem and i solved it with these 3 steps:

1) in Apache config file (for me the path was C:\wamp\bin\apache\apache2.4.18\conf\httpd.conf) add the line: Header set Access-Control-Allow-Origin "*" in the content of the <Directory> tag:

DocumentRoot "c:/wamp/www"
<Directory "c:/wamp/www/">
    Options +Indexes +FollowSymLinks
    Header set Access-Control-Allow-Origin "*"
    AllowOverride all
    Require local
</Directory>

2) activate the "headers_module" in apache's modules (it will also restart your apache server, effectively applying the change made in step 1)

3) clear your browser cache (I am using chrome and i was told the best way to "hard clear" the cache was to go in the developper tools -> Networks tab -> right click -> clear browser cache) (by the way, clearing the browser cache is often useful when debugging in chrome)

Now it should work. Good luck !

like image 40
baldychristophe Avatar answered Sep 20 '22 12:09

baldychristophe