示例#1
0
        public async Task <AuthorList> postAuthorsAsync(AuthorQueryCondition _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}/authors{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 <AuthorList>(content));
        }
示例#2
0
        public AuthorList postAuthors(AuthorQueryCondition _obj, int?_page = null, int?_per_page = null)
        {
            Task <AuthorList> t = postAuthorsAsync(_obj, _page, _per_page);

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