具有基本身份验证的Angular7 / Ionic get / post http不起作用

时间:2019-06-18 07:51:36

标签: angular

在我的项目中,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 });

0 个答案:

没有答案