【问题标题】:How to enable CORS with PHP如何使用 PHP 启用 CORS
【发布时间】:2017-11-25 04:11:19
【问题描述】:

我有一个 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 上做到这一点。

【问题讨论】:

标签: php cors wamp


【解决方案1】:

正如所评论的,问题是您需要允许脚本的所有来源。

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

【讨论】:

    猜你喜欢
    • 2014-01-19
    • 2015-08-13
    • 2015-04-26
    • 2012-07-27
    • 2017-08-26
    • 2021-07-07
    相关资源
    最近更新 更多