Example #1
0
        public static async Task <Tuple <System.Net.HttpStatusCode, T> > PostHttpContentAsync <T>(this IRequestProvider p, string uri, string token, HttpContent hc)
        {
            var httpclient = p.CreateHttpClient(token: token);


            // var requestMessage = new HttpRequestMessage(HttpMethod.Post, uri) { Content = hc };



            var response = await httpclient.PostAsync(uri, hc);


            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var resultstring = await response.Content.ReadAsStringAsync();

                T result = await Task.Run(() =>
                                          JsonConvert.DeserializeObject <T>(resultstring));


                return(new Tuple <System.Net.HttpStatusCode, T>(response.StatusCode, result));
            }
            else
            {
                return(new Tuple <System.Net.HttpStatusCode, T>(response.StatusCode, default(T)));
            }
        }