Xamarin.Forms HttpClient send get request using a simple fourSquare API-KEY

374 views Asked by At

I am trying to get a connection to the Places AIP of foursquare. (https://developer.foursquare.com/reference/place-search) This needs me the send the following authorization header:

{ "Authorization" : "<API_KEY>"} and not { "Authorization" : "<SOME_SCHEMA> <API_KEY>"} SOME_SCHEMA being "Basic", "Key" or any other type. --header 'Authorization: API_KEY'

I tried to set is like so client.DefaultRequestHeaders.Authorization = new

AuthenticationHeaderValue(Constants.API_KEY);

According to MSDN documentation this should work. but all I get is an exception saying that the header type is invalid..

Spend the day trying to found a way. but nothing I tried so far works.

I did text over curl and my api-key is good and so is the request. I really just need to get the HttpClient to accept not having a schema/type for Authorization.

1

There are 1 answers

1
Nissaba On BEST ANSWER

This works. it will allow to have a authorization header that does not contain an auth type.

var request = new HttpRequestMessage(HttpMethod.Get, url);

                request.Headers.Add("Accept", "application/json");
                request.Headers.TryAddWithoutValidation("Authorization", Constants.API_KEY);