We have an Azure WebApi service that can sometimes return a BadRequest, for example,
return BadRequest("{\"errors\":[{\"message\":\"MyBuddy not found!\",\"code\":9}]}");
The problem is that on Xamarin.Android, using System.Net.Http.HttpClient, the content of the response 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 the Swagger user interface, and there is response content there, for example:
{ "errors": [ { "message": "MyBuddy not found!", "code": 9 } ] }
Is it normal that the content of the BadRequest response is empty on Xamarin.Android? Is there anything I can do, for example. configure HttpClient differently to get StringContent?
EDIT: we are using AndroidClientHandler . To do this, we added a text file to the Android project, installed its BuildAction on AndroidResource and its contents on XA_HTTP_CLIENT_HANDLER_TYPE=Xamarin.Android.Net.AndroidClientHandler
source share