Example #1
0
 public void AddJsonAndToken(HttpClient client, string json, bool withToken)
 {
     if (withToken)
     {
         client.AddQueryStr(TOKEN, GlobalVar.AccessToken);
     }
     if (!string.IsNullOrEmpty(json))
     {
         client.AddQueryStr(JSON, json);
     }
 }
Example #2
0
        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());
        }
Example #3
0
        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());
        }