Пример #1
0
        internal static T APICaller <T>(BaseAPI api, Method method)
            where T : class
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    // todo - refactoring
                    client.DefaultRequestHeaders.Add("Accept", "application/xml");
                    client.DefaultRequestHeaders.Add("User-Agent", "covid");

                    var response = client.GetAsync(api.RequestURL).Result;
                    response.EnsureSuccessStatusCode();

                    var result = response.Content.ReadAsStringAsync().Result;

                    result = XmlConverter.ConvertXmlToJson(result);

                    return(JsonConvert.DeserializeObject <T>(result, new CovidConverter <T>()));
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }