public static List <T> Get(string url, int id = 0, bool isListaObj = true)
        {
            var client = SingletonHttpClient.GetInstanceHttpClient;
            var _url   = id > 0 ? url + "/" + id : url;

            var responseTask = client.GetAsync(_url);

            responseTask.Wait();

            var      result    = responseTask.Result;
            List <T> resultado = null;

            if (result.IsSuccessStatusCode)
            {
                var readTask = result.Content.ReadAsStringAsync();
                readTask.Wait();

                if (isListaObj)
                {
                    resultado = BaseSerialize <T> .DeserializeListObject(readTask.Result);
                }
                else
                {
                    resultado = new List <T>()
                    {
                        BaseSerialize <T> .DeserializeObject(readTask.Result)
                    };
                }
            }
            return(resultado);
        }
        public static bool Put(T t, string url)
        {
            var client = SingletonHttpClient.GetInstanceHttpClient;

            var postTask = client.PutAsync(url, new StringContent(
                                               BaseSerialize <T> .SerializeObject(t),
                                               Encoding.UTF8,
                                               "application/json"));

            postTask.Wait();

            var result = postTask.Result;

            return(result.IsSuccessStatusCode);
        }
Exemplo n.º 3
0
 public Inject(BaseWeb webRequest, BaseSerialize serialize)
 {
     _webRequest = webRequest;
     _serialize  = serialize;
 }