Ejemplo n.º 1
0
        public static async Task <T> Get <T>(string apiUrl)
        {
            T result = default(T);

            AttachAuthorizationToken();
            var response = await WebEngine.ClientInstance.GetAsync(AppConfigHelper.GetString("WebServiceUrl") + apiUrl);

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                result = JsonConvert.DeserializeObject <T>(content);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static async Task <bool> Post(string apiUrl, object requestData, Action <string> onSuccess = null, Action <string> onFailed = null)
        {
            AttachAuthorizationToken();
            var response = await WebEngine.ClientInstance.PostAsync(AppConfigHelper.GetString("WebServiceUrl") + apiUrl,
                                                                    new StringContent(JsonConvert.SerializeObject(requestData), new UnicodeEncoding(), "application/json"));

            var content = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                onSuccess?.Invoke(content);
                return(true);
            }
            else
            {
                onFailed?.Invoke(content);
                return(false);
            }
        }
Ejemplo n.º 3
0
        public static async Task <T> Post <T>(string apiUrl, object requestData)
        {
            AttachAuthorizationToken();
            T   result;
            var response =
                await
                WebEngine.ClientInstance.PostAsync(AppConfigHelper.GetString("WebServiceUrl") + apiUrl,
                                                   new StringContent(JsonConvert.SerializeObject(requestData), new UnicodeEncoding(), "application/json"));

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                result = JsonConvert.DeserializeObject <T>(content);
            }
            else
            {
                var content = await response.Content.ReadAsStringAsync();

                throw new ServiceCallException(content);
            }

            return(result);
        }