private async void BtnGetWebApi_Click(object sender, EventArgs e)
{
try
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:5135/api/");
//HTTP GET
var response = await client.GetAsync("Anagraficas");
if (response.IsSuccessStatusCode)
{
var listAnagrafica = await response.Content.ReadFromJsonAsync<IList<Anagrafica>>();
dataGridView1.DataSource
= listAnagrafica;
}
else
{
var listAnagrafica = Enumerable.Empty<Anagrafica>();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Le opere pubblicate in questo blog sono sotto la licenza Creative Commons. Attribuzione- No commerciale e no derivate.
Nessun commento:
Posta un commento