Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular no overload matches this call

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 ?

like image 325
Ali Ghassan Avatar asked Dec 28 '25 15:12

Ali Ghassan


1 Answers

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)
});
like image 100
joyBlanks Avatar answered Dec 30 '25 20:12

joyBlanks