(3)WebApi客户端调用
1.创建一个应用台控制程序,可以把Model的引用,用下面的方法拖拽上来(解决方案里没有这个文件,只是这个文件的引用)
![](https://images2015.cnblogs.com/blog/196558/201612/196558-20161226101120961-1405618498.png)
2.Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using TmplWebApiDemo.Models;
namespace TempWebApiClient
{
class Program
{
static void Main(string[] args)
{
Do();
Console.ReadLine();
}
private static async void Do()
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:12268/");
var result = await client.GetAsync("students");
var list = await result.Content.ReadAsAsync<IEnumerable<Student>>();
foreach (var item in list)
{
Console.WriteLine(item.Name);
}
}
}
}
![](https://images2015.cnblogs.com/blog/196558/201612/196558-20161226101121820-1116020856.png)