1. Nuget
PM> install-package Laojiu.WebApiClient
[HttpHost("http://www.webapiclient.com")]
public interface MyWebApi : IDisposable
{
// GET webapi/user?account=laojiu
// Return 原始string内容
[HttpGet("/webapi/user")]
ITask<string> GetUserByAccountAsync(string account);
// POST webapi/user
// Body Account=laojiu&password=123456
// Return json或xml内容
[HttpPost("/webapi/user")]
ITask<UserInfo> UpdateUserWithFormAsync([FormContent] UserInfo user);
}
public class UserInfo
{
public string Account { get; set; }
[AliasAs("password")]
public string Password { get; set; }
[IgnoreSerialized]
public string Email { get; set; }
}
static async Task TestAsync()
{
var myWebApi = HttpApiClient.Create<MyWebApi>();
var user = new UserInfo { Account = "laojiu", Password = "123456" };
var user1 = await myWebApi.GetUserByAccountAsync("laojiu");
var user2 = await myWebApi.UpdateUserWithFormAsync(user);
}
- 加群439800853 注明WeApiClient
- [email protected],不重要的尽量不要发