【问题标题】:file uploading has been blocked by CORS policy文件上传已被 CORS 策略阻止
【发布时间】:2020-05-08 05:51:19
【问题描述】:

我正在尝试通过角度 ng2-file upload 上传文件。

我有 2 个本地服务器:

http://localhost:4200 用于 angularhttp://localhost 提供 php 文件

当我将文件发送到 php 服务器进行上传时出现错误:

从源访问“http://127.0.0.1/index.php”处的 XMLHttpRequest “http://localhost:4200”已被 CORS 策略阻止:响应 预检请求未通过访问控制检查:否 请求中存在“Access-Control-Allow-Origin”标头 资源。

【问题讨论】:

标签: angular file upload


【解决方案1】:

在您的 php 中添加以下标头:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, DELETE, PUT');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization');
header('Access-Control-Allow-Credentials: true');

【讨论】:

    猜你喜欢
    • 2019-11-25
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 2021-09-05
    • 2021-10-13
    • 2019-11-01
    • 2023-04-10
    • 2022-08-03
    相关资源
    最近更新 更多