在我的项目中,API具有基本身份验证。该API在Postman中完美运行,当我使用Angular 7调用API时,出现以下错误?
core.js:15724错误HttpErrorResponse {headers:HttpHeaders,状态: 0,statusText:“未知错误”,网址: “ http://localhost/basicapi/index.php”,
let userName = 'abx';let password = 'hsn';let authorizationData = 'Basic ' + btoa(userName + ':' + password); const headerOptions = new HttpHeaders({ 'Access-Control-Allow-Origin' : '*', 'Content-Type' : 'application/json', 'Authorization': authorizationData, }) return this.http.get('http://localhost/basicapi/index.php', { headers: headerOptions });