我正在尝试添加一个请求的标头来接收来自API的数据,该API请求具有我的密钥值的特定授权名称 . 我花了好几个小时 . 如果我使用谷歌浏览器的插件手动添加名称和值,该请求将起作用 . 我有一个服务,我用来运行get请求从API中提取,但API请求请求标头 . 有任何想法吗?

从'@ angular / core'导入;从'@ angular / common / http'导入{HttpClient,HttpErrorResponse,HttpHeaders};从'rxjs'导入{Observable,BehaviorSubject,combineLatest,Subject};从'rxjs / operators'导入{map,take,merge,switchMap};

@Injectable({providedIn:'root'})导出类CjaffiliateService {

constructor(public http: HttpClient) { }
  headerName = 'authorization';
  // tslint:disable-next-line:max-line-length
  key = 'key'
  cjURL = 'wwww.url.used';

  getAdvertisers() {
    let headers: HttpHeaders = new HttpHeaders();
    headers = headers.append('Content-Type', 'application/json');
    headers = headers.append(this.headerName, this.key);
    const options = {headers};
    console.log(headers);
    const getRequest = this.http.get(this.cjURL, options);
    const subscription = getRequest.subscribe((x) => console.log(x));
    console.log(getRequest);
    return getRequest;
  }
}