Esempio n. 1
0
        public async Task <AddressList> postAddressesAsync(AddressQueryCondition _obj, int?_page = null, int?_per_page = null)
        {
            var client      = new ServantClient();
            var queryparams = new List <string> {
                _page.HasValue ? $"_page={_page.Value}" : null,
                _per_page.HasValue ? $"_per_page={_per_page.Value}" : null,
            }.Where(e => !string.IsNullOrEmpty(e));
            var qp = queryparams.Count() > 0 ? $"?{string.Join("&", queryparams)}" : "";

             #if DEBUG
            var jsonObj = JsonConvert.SerializeObject(_obj, Formatting.Indented);
             #else
            var jsonObj = JsonConvert.SerializeObject(_obj);
             #endif
            var res = await client.PostAsync($"{server}/addresses{qp}", new StringContent(jsonObj, Encoding.UTF8, "application/json"));

            Debug.WriteLine($">>> {res.RequestMessage}");
            Debug.WriteLine($"-----");
            Debug.WriteLine(jsonObj);
            Debug.WriteLine($"-----");
            Debug.WriteLine($"<<< {(int)res.StatusCode} {res.ReasonPhrase}");
            var content = await res.Content.ReadAsStringAsync();

            Debug.WriteLine($"<<< {content}");
            return(JsonConvert.DeserializeObject <AddressList>(content));
        }
Esempio n. 2
0
        public AddressList postAddresses(AddressQueryCondition _obj, int?_page = null, int?_per_page = null)
        {
            Task <AddressList> t = postAddressesAsync(_obj, _page, _per_page);

            return(t.GetAwaiter().GetResult());
        }