0

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?

Gold.strike
  • 1,269
  • 13
  • 47
  • use wireshark or another tool to examine the different requests and figure out what is triggering the 400 – Jason Apr 29 '21 at 13:47
  • I've tried this with Charles Proxy, but I wasn't able to decode the requests. I will try with wireshark to compare. – Gold.strike Apr 29 '21 at 14:27
  • Install the Charles root cert on your device if you want to decode the contents of your requests if they are over SSL. – Cheesebaron Apr 30 '21 at 22:14

0 Answers0