Javascript 如何创建一个fetch函数来从需要身份验证头的api获取json数据?

Javascript 如何创建一个fetch函数来从需要身份验证头的api获取json数据?,javascript,angular,ionic4,Javascript,Angular,Ionic4,我正在使用rapidapi从一个足球应用程序中获取一些数据,但我能理解为什么会抛出这个错误 我已经尝试过这段代码,但它不起作用,这显示了这种类型的错误 Response { type: "cors", url: "https://soccer-livescore.p.rapidapi.com/v1/global/getleague?league=Indo%20D3", redirected: false, status: 403, ok: false, statusText: "Forbidde

我正在使用rapidapi从一个足球应用程序中获取一些数据,但我能理解为什么会抛出这个错误

我已经尝试过这段代码,但它不起作用,这显示了这种类型的错误

Response { type: "cors", url: "https://soccer-livescore.p.rapidapi.com/v1/global/getleague?league=Indo%20D3", redirected: false, status: 403, ok: false, statusText: "Forbidden", headers: Headers, body: ReadableStream, bodyUsed: false }

您缺少RapidAPI应用程序密钥。转到以了解如何获取API应用程序密钥。我尝试过,但应将API应用程序密钥放在何处?标头(“X-RapidAPI-key”,{API-key})
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-matches',
  templateUrl: './matches.page.html',
  styleUrls: ['./matches.page.scss'],
})
export class MatchesPage implements OnInit {

  constructor(public http: HttpClient){}

  ngOnInit() {


fetch("https://soccer-livescore.p.rapidapi.com/v1/global/getleague?league=Indo%20D3", {
    "method": "GET",
    "headers": {
        "x-rapidapi-host": "soccer-livescore.p.rapidapi.com",
        "x-rapidapi-key": "not showing my rapid key"
    }
})

.then(response => {
    console.log(response);
})
.catch(err => {
    console.log(err);
});
  }

}