Enable CORS with wamp on windows 8

守給你的承諾、 提交于 2019-11-27 03:24:24

问题


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!


回答1:


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.




回答2:


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 !



来源:https://stackoverflow.com/questions/27058104/enable-cors-with-wamp-on-windows-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!