public async virtual Task <T> GetAsync <T, TR>(string Url, TR tParameter, QueryInstance query) where T : class where TR : class
        {
            try
            {
                if (query.CheckParameter())
                {
                    return(null);
                }
                var host = await GetHostsAsync(query);

                var client = ExtendClass.GetHttpClient(ClientFactory, nameof(NacosHttpClient), host, Nacos.Value.EnableSSL);
                Url = Url.GetUrl(ExtendClass.SetMethodParameter(tParameter));
                var httpResponse = await client.GetAsync(Url);

                var resultStr = await httpResponse.Content.ReadAsStringAsync();

                var result = resultStr.ToJson <T>();
                return(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(MethodInfo.GetCurrentMethod().Name + ":" + ex.Message);
                return(null);
            }
        }
        public async virtual Task <T> PostAsync <T, TR>(string Url, TR tParameter, QueryInstance query) where T : class where TR : class
        {
            try
            {
                if (query.CheckParameter())
                {
                    return(null);
                }
                var host = await GetHostsAsync(query);

                var client  = ExtendClass.GetHttpClient(ClientFactory, nameof(NacosHttpClient), host, Nacos.Value.EnableSSL);
                var content = ExtendClass.SetMethodJsonParameter(tParameter);
                content.Headers.Clear();
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json")
                {
                    CharSet = "utf-8"
                };
                var httpResponse = await client.PostAsync(Url, content);

                var resultStr = httpResponse.Content.ReadAsStringAsync().Result;
                var result    = resultStr.ToJson <T>();
                return(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(MethodInfo.GetCurrentMethod().Name + ":" + ex.Message);
                return(null);
            }
        }
Exemple #3
0
        public async Task <ServiceList> Queryinstances(QueryInstance query)
        {
            if (query.CheckParameter())
            {
                return(null);
            }
            var url   = InterfaceConst.Queryinstances;
            var model = await GetAsync <QueryInstance, ServiceList>(url, query, MethodBase.GetCurrentMethod().Name, typeof(ServiceList));

            return(model);
        }