public void AddJsonAndToken(HttpClient client, string json, bool withToken) { if (withToken) { client.AddQueryStr(TOKEN, GlobalVar.AccessToken); } if (!string.IsNullOrEmpty(json)) { client.AddQueryStr(JSON, json); } }
public ApiResultModel Delete(string json, string action = ACTION_DELETE, bool withToken = true, string mac = null) { HttpResponseMessage response; using (HttpClient client = CreateClient(action)) { AddJsonAndToken(client, json, withToken); client.AddQueryStr(SHOPID, GlobalVar.ShopId.ToString()); client.AddQueryStr(MAC, mac ?? CreateMac(json)); response = client.GetAsync(client.BaseAddress).Result; } return(response.ParseResult()); }
public ApiResultModel Get(string json = "", string action = ACTION_GET, bool withToken = true, string mac = null, int pageIndex = 0, int pageSize = 0, string orderBy = "Id", bool asc = true) { HttpResponseMessage response; using (HttpClient client = CreateClient(action)) { AddJsonAndToken(client, json, withToken); client.AddQueryStr(SHOPID, GlobalVar.ShopId.ToString()); client.AddQueryStr(MAC, mac ?? CreateMac(json)); if (pageIndex > 0 && pageSize > 0) { client.AddQueryStr("pageindex", pageIndex.ToString()); client.AddQueryStr("pagesize", pageSize.ToString()); client.AddQueryStr("orderby", orderBy); client.AddQueryStr("asc", asc.ToString()); } response = client.GetAsync(client.BaseAddress).Result; } return(response.ParseResult()); }