angular - ng2-file-upload 不适用于 Angular 6
问题描述
我正在使用 Angular 6 中的 ng2-file-upload 包。我的后端是 PHP。
我可以选择文件,但是当我尝试单击上传时出现此错误:
Failed to load [api url]: Response to preflight request doesn't pass
access control check: The value of the 'Access-Control-Allow-Origin'
header in the response must not be the wildcard '*' when the request's
credentials mode is 'include'. Origin 'http://localhost:4200' is
therefore not allowed access. The credentials mode of requests
initiated by the XMLHttpRequest is controlled by the withCredentials
attribute.
在我的 API 中添加了标头
header('Access-Control-Allow-Origin','http://localhost:4200/');
header('Access-Control-Allow-Methods', 'POST');
header('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
header('Access-Control-Allow-Credentials', true);
仍然有同样的问题。
谢谢。
解决方案
您可以添加这些而不是您正在使用的
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, PATCH');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token , Authorization');
header('Access-Control-Max-Age: 1728000');
预检option
请求被拒绝,因为您不允许该方法。
推荐阅读
- firebase - 我正在尝试在颤振中使用日期选择器并将我的日期存储到云火库中。但我的日期显示为空
- python - 在 VS Code 中自动重新格式化 Python 代码
- prolog - 如何从 GNU prolog 中的列表中读取?
- python - 如何将'n'个数组保存到'n'个npy文件?
- awk - awk: gsub("\\\\", "\\\\") 产生令人惊讶的结果
- javascript - D3js drag() returns strange results on chrome
- graph - 我如何证明图同构问题是否属于 np 问题?
- python - 计算图像之间的距离?
- c++ - ld:为变量模板报告架构 arm64 的重复符号
- arangodb - 阿兰戈德。我可以在 PHRASE 搜索中使用 LOWER() 吗?