Xamarin.Forms: default instead of AndroidClientHandler as HttpClient implementation

646 Views Asked by At

I work on an existing Xamarin.Forms app, where we need to integrate API calls to external providers.

For this, we use my client's custom HttpClient library.

Until now, the Android HttpClient was set to AndroidClientHandler.

But after a basic call to a provider's API, we get a "400 - bad request" answer:

HttpContent content = new StringContent(string.Empty);
if (tObject != null)
{
    string data = JsonSerializer.Serialize(tObject, new JsonSerializerOptions() { IgnoreNullValues = true, IgnoreReadOnlyProperties = true });

    content = new StringContent(data, Encoding.UTF8, "application/json");
}
HttpResponseMessage apiResponse = await _client.PostAsync(route, content);
string responseData = await apiResponse.Content.ReadAsStringAsync();

If we set the Android HttpClient to default, all works fine.

But it seems that it's better choice to use the AndroidClientHandler. So would you have suggestions to investigate and identify the issue related to the AndroidClientHandler?

0

There are 0 best solutions below