Reputation: 1
Here is my API localhost:51549/API/student/
I want it to be displayed in my form when the button is clicked as a data grid. I have tried:
private void button1_Click_1(object sender, EventArgs e)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:51549/");
HttpResponseMessage response = client.GetAsync("api/student").Result;
dataGridView1.DataSource = response;
}
Note: my student controller basically calls a DLL to do the operations.
Upvotes: 0
Views: 1096
Reputation: 410
You have to write the content of the response to the DataSource:
dataGridView1.DataSource = response.Content.ReadAsStringAsync().Result;
Upvotes: 1