I am a beginner in Xamarin development and I just tried Xamarin.Forms to Develop Android & iOS App with shared Code, and what I'm trying to do here is to get data from API with Plugin.RestClient NuGet package.
Here is the MainViewModel. '''
public MainViewModel()
{
InitializeDataAsync();
}
private async Task InitializeDataAsync()
{
var vehicleServices = new VehicleServices();
VehicleList = await vehicleServices.GetVehiclesAsync();
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
''' The services '''
public async Task<List<Vehicle>> GetVehiclesAsync()
{
RestClient<Vehicle> restClient = new RestClient<Vehicle>();
var vehicleList = await restClient.GetAsync();
return vehicleList;
}
''' And RestClient '''
private const string WebServiceUrl = "https://localhost:44355/api/Vehicles";
public async Task<List<T>> GetAsync()
{
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var httpClient = new HttpClient();
var json = await httpClient.GetStringAsync(WebServiceUrl);
var vehicles = JsonConvert.DeserializeObject<List<T>>(json);
return vehicles;
}
''' I can see my Debug for the url and json response. But on my Android Emulator there is nothing on the list. I also already add internet permission on my Android Manifest. Anyone have ideas on what to do?