This is my Code and i Can't fatch data from api in xamarin.
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
{
public MainPage()
{
InitializeComponent();
}
public static List getPersons()
{
List lp = new List();
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
try
{
HttpResponseMessage response = client.GetAsync("http://localhost:51949/api/employee").Result;
if (response.IsSuccessStatusCode)
{
lp = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result).ToList();
}
}
catch
{
{
List lp = new List();
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
try
{
HttpResponseMessage response = client.GetAsync("http://localhost:51949/api/employee").Result;
if (response.IsSuccessStatusCode)
{
lp = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result).ToList();
}
}
catch
{
}
return lp;
}
private async void Button_Clicked(object sender, EventArgs e)
{
var list = getPersons();
await Navigation.PushAsync(new ListOfEmployee());
}
}
}
private async void Button_Clicked(object sender, EventArgs e)
{
var list = getPersons();
await Navigation.PushAsync(new ListOfEmployee());
}
}
Mushtaq M APosted Jan 27, 2019, 1:31 AM
Ahsan SiddiquePosted Dec 4, 2018, 4:41 AM