l am try to get data Json api from flightaware using Angular . And all requests from flightaware must include a username and FlightXML Key using basic HTTP Authentication standard .
Code
var fxml_url = 'http://flightxml.flightaware.com/json/FlightXML2/';
var username = 'YOUR_USERNAME';
var apiKey = 'YOUR_APIKEY';
this.http.get(fxml_url + 'MetarEx', {
username: username,
password: apiKey,
query: {airport: 'KAUS', howMany: 1}
}).subscribe(data=>{
console.log(data)
})
but l get error is
No overload matches this call.
The last overload gave the following error.
Argument of type '{ username: string; password: string; query: { airport: string; howMany: number; }; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }'.
Object literal may only specify known properties, and 'username' does not exist in type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }'.
any idea please ?
From docs: However, with some libraries it may be necessary to manually encode the "user:key" in base64 and send the result in the "Authorization" header as part of each HTTP request
var fxml_url = 'http://flightxml.flightaware.com/json/FlightXML2/';
var username = 'YOUR_USERNAME';
var apiKey = 'YOUR_APIKEY';
var auth = btoa(`${username}:${apiKey}`);
this.http.get(fxml_url + 'MetarEx', {
headers: { Authorization: auth },
params: new HttpParams({fromObject: { airport: 'KAUS', howMany: '1' }})
}).subscribe(data=>{
console.log(data)
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With