我需要从 Angular 8 应用程序访问 Sonarqube Api,但我的请求调用失败,我尝试了以下方式:
应用服务.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable()
export class AppService {
constructor(private http: HttpClient) { }
private baseUrl:string = 'https://sonarqube.[domain].com';
private issueSearch:string = '/api/issues/search?'
getIssues() {
const url:string = 'https://sonarqube.[domain].com//api/issues/search?[queryparams]'
return this.http.get(url);
}
}
Auth token 是在 sonarqube-->My Account -->Security 中生成的
Authintercepter.ts
import {Injectable} from '@angular/core';
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest} from '@angular/common/http';
import {Observable} from "rxjs";
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor(){
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
req = req.clone({
setHeaders: {
Authorization: `Basic AUTH_TOKEN`
}
});
return next.handle(req);
}
}
但我无法通过这种方式进行身份验证,知道这里出了什么问题吗?
提前致谢。