FlightAware Discussions

Authorization Required .Net Core

string fxmlUrl = “http://flightxml.flightaware.com/json/FlightXML2”;
string username =“mabdullah”;
string apiKey =“B44***”;

        var uriBuilder = new UriBuilder(fxmlUrl);
       var requestUrl = fxmlUrl
            .AppendPathSegment("AirportInfo")
            .SetQueryParams(new { airportCode = "KIAH" });
       var serializer =new DataContractJsonSerializer(typeof(AirportInfoResult));
       var client =new HttpClient();
       var credentials = Encoding.ASCII.GetBytes(username +":" + apiKey);

        client.DefaultRequestHeaders.Authorization =new AuthenticationHeaderValue("Basic", Convert.ToBase64String(credentials));
       var streamTask = client.GetStreamAsync(requestUrl.ToString()).Result;
       var airportInfo = serializer.ReadObject(streamTask)as AirportInfoResult;
        Console.WriteLine(airportInfo.AirportResult.Code);

The Authorization Required error indicates that the username or API key is incorrect. Please verify that you have supplied the correct value for your API Key. All API keys are lowercase, it looks like yours may have been given a capital letter at some point when copying it into the example.