We have an Azure WebApi service that can sometimes return a BadRequest like so
return BadRequest("{\"errors\":[{\"message\":\"MyBuddy not found!\",\"code\":9}]}");
The problem is that on Xamarin.Android, using the System.Net.Http.HttpClient, the response content that we receive is empty.
This is our code:
private static async Task<int> ReadErrorCodeAsync(HttpResponseMessage response)
{
var x = response.ReasonPhrase;
var errorSerialized = await response.Content.ReadAsStringAsync();
var error = JObject.Parse(errorSerialized);
return ((JArray)error["errors"])[0]["code"].Value<int>();
}
But errorSerialized is always an empty string. We also use a Swagger UI and there the response content is what we expect, e.g.:
{
"errors": [
{
"message": "MyBuddy not found!",
"code": 9
}
]
}
Is it normal that the Content of a BadRequest reponse is empty on Xamarin.Android? Is there anything I can do, e.g. configure the HttpClient differently, so that I receive the StringContent?
EDIT: we're using the AndroidClientHandler. For this we've added a text file to the Android project, set its BuildAction to AndroidResource and its content to XA_HTTP_CLIENT_HANDLER_TYPE=Xamarin.Android.Net.AndroidClientHandler