如何使用PHP启用COR



我有一个Angular 4应用程序与位于我本地计算机上的Wamp(www文件夹)上的PHP脚本。登录脚本时,我会在浏览器中登录此错误。

No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://localhost:4200' is therefore not allowed access. 
The response had HTTP status code 404.

我知道这是因为我试图从Localhost到Localhost访问此问题。

我做了一些阅读,看来我需要从WAMP服务器修复它。不确定如何在Wamp上做到这一点。

正如所评论的,问题在于您需要允许脚本中的所有起源。

//at the very begining of your php script.
header('Access-Control-Allow-Origin: *'); 

对我来说,我正在尝试其他答案,它由于某种原因而没有起作用,但是我尝试了下面的一个,它可以使用:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers:  Content-Type, X-Auth-Token, Authorization, Origin');
header('Access-Control-Allow-Methods:  POST, PUT, GET');

最新更新