Every time I tried to consume my web Api with my android emulator, It doesn't work.
I tried the simple get values but It didn't work :
public async void Test()
{
HttpClient httpClient = this.HttplicentAccount;
var uploadServiceBaseAdress = "https://192.168.0.19:44336/api/values";
var value = await httpClient.GetAsync(uploadServiceBaseAdress);
var status = value.StatusCode;
Console.WriteLine(status);
}
I use :
private HttpClient _httpClient;
public HttpClient HttplicentAccount
{
get
{
_httpClient = _httpClient ?? new HttpClient
(
new HttpClientHandler()
{
ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) =>
{
//bypass
return true;
},
}
, false
)
{
BaseAddress = new Uri("https://192.168.0.19:44336"),
};
// In case you need to send an auth token...
//_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Authorization", "YOUR_TOKEN");
return _httpClient;
}
}
To Counter the certficate error.
I tried on swagger and the get values was working. But for example When I am starting my android emulator to test my web api is stuck, don't work.