簡體   English   中英

ng2-file-upload不適用於angular 6

[英]ng2-file-upload is not working with 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請求被拒絕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM