(3)WebApi客户端调用
生活随笔
收集整理的這篇文章主要介紹了
(3)WebApi客户端调用
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.創(chuàng)建一個(gè)應(yīng)用臺控制程序,可以把Model的引用,用下面的方法拖拽上來(解決方案里沒有這個(gè)文件,只是這個(gè)文件的引用)
2.Program.csusing 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); } } }}
null
2.Program.csusing 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); } } }}
null
轉(zhuǎn)載于:https://www.cnblogs.com/tangge/p/6221371.html
總結(jié)
以上是生活随笔為你收集整理的(3)WebApi客户端调用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C# 去除文件和文件夹的只读属性
- 下一篇: 接口测试总结2