我在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);
仍然有同样的问题。
谢谢。
答案 0 :(得分:0)
您可以添加这些内容而不是使用的内容
taskType
.pipe(
concatMap(tasks => {
const observables = [];
for (const task of tasks) {
observables.push(this.auth.getUserById(task.assigned_id));
}
return forkJoin(...observables).pipe(
map(innerResults => ({
innerResults,
tasks
}))
);
})
)
.subscribe(({ innerResults, tasks }) => ...);
预检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');
请求被拒绝,因为您不允许该方法。