1.创建一个应用台控制程序,可以把Model的引用,用下面的方法拖拽上来(解决方案里没有这个文件,只是这个文件的引用)

(3)WebApi客户端调用-LMLPHP


 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);
            }
        }
    }
} 
(3)WebApi客户端调用-LMLPHP
 



04-19 21:37