Issue
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.
Solution
Nevermind, I fixed the issues : https://docs.microsoft.com/fr-fr/xamarin/cross-platform/deploy-test/connect-to-local-web-services
I created a new webApi project without https but it must be the same thing with https. Solution : I should write http://10.0.2.2:"port" instead of my previous ip, to connect with my wep Api Server in localhost. Ty for your help.
Answered By - guiz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.