文件上传已被 CORS 策略阻止
file uploading has been blocked by CORS policy
我正在尝试通过 angular ng2-file upload 上传文件。
我有 2 个本地服务器:
http://localhost:4200 for angular and http://localhost 提供 php 个文件
当我将文件发送到 php 服务器进行上传时出现错误:
Access to XMLHttpRequest at 'http://127.0.0.1/index.php' from origin
'http://localhost:4200' has been blocked by CORS policy: Response to
preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource.
在您的php中添加以下headers:
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');
我正在尝试通过 angular ng2-file upload 上传文件。
我有 2 个本地服务器:
http://localhost:4200 for angular and http://localhost 提供 php 个文件
当我将文件发送到 php 服务器进行上传时出现错误:
Access to XMLHttpRequest at 'http://127.0.0.1/index.php' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
在您的php中添加以下headers:
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');