コード例 #1
0
        private async Task <TRes> ProcessRequestAsync <TReq, TRes>(HttpClient client, TReq request, ApiPathsBase path)
        {
            string uri = path.GetEndPoint();

            HttpResponseMessage resp = null;

            if (request == null)
            {
                throw new Exception($"Object request can't be null in a {path.GetHttpMethod()} request");
            }

            if (path.GetHttpMethod() == HttpMethod.Post)
            {
                string objectSerialized = request.ToJsonString(namingStrategy);
                var    contentToSend    = new StringContent(objectSerialized, Encoding.UTF8, "application/json");

                resp = await ProcessPostRequestAsync(contentToSend, path, client);
            }

            if (resp == null)
            {
                throw new HttpRequestException($"{path.GetHttpMethod()} is not a valid request.");
            }

            string result = await resp.Content.ReadAsStringAsync();

            var response = result.ToObject <TRes>(namingStrategy);

            return(response);
        }
コード例 #2
0
 private async Task <HttpResponseMessage> ProcessPostRequestAsync(StringContent contentToSend, ApiPathsBase path, HttpClient client)
 {
     return(await client.PostAsync(path.GetEndPoint(), contentToSend));
 }