将RapidAPI与Angular一起使用



我正在尝试使用Rapidapi中的SkyScanner API和Angular来搜索航班价格。这是我的代码

headers = new Headers();
url:string;

constructor(private _http:HttpClient,) {
this.headers.append('X-RapidAPI-Key', 'MY-KEY');
this.url = 'https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/browseroutes/v1.0/IE/EUR/en-GB/{here should be other parameters like destination}' }

我从输入开始从、到、天、月和年

getFlightDetail(from,to,day,month,year) : Observable<Iflight>{
return this._http.get<Iflight>(this.url+this.headers)
.pipe(
tap(data => console.log('flightData/error' + JSON.stringify(data))
),
catchError(this.handlerError)
);
}

问题是当我运行应用程序时,我得到了

401未经授权的

x-rapidapi-host标头丢失。如果您使用RapidAPI、x-rapidapi-keyx-rapidapi-host,还需要添加两个自定义标头

另外,我假设您已经订阅了Skyscanner API。

最新更新