[英]ng2-file-upload is not working with angular 6
I am wroking with ng2-file-upload package in angular 6. I had my backend in PHP. 我在Angular 6中使用ng2-file-upload软件包。我的后端使用PHP。
I am able to select file but when I try to click on upload getting this error: 我可以选择文件,但是当我尝试单击上载时出现此错误:
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.
Added Header to my API 将标题添加到我的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);
Still have the same problem. 仍然有同样的问题。
Thanks. 谢谢。
You can add these instead of what you are using 您可以添加这些而不是您正在使用的内容
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');
preflight option
request is rejected as you are not allowing that method. 因为您不允许该方法,所以预检
option
请求被拒绝。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.