Exemplo n.º 1
0
        public async Task <Tuple <HttpResponseMessage, R> > PostDataAsync <T, R>(string url, T data) where R : class
        {
            var json = await _json.SerializeAsync(data);

            var response = await _httpClient.PostAsync(url, JsonContent(json));

            if (response.StatusCode == HttpStatusCode.OK)
            {
                var returnJson = await response.Content.ReadAsStringAsync();

                return(new Tuple <HttpResponseMessage, R>(response, await _json.DeserializeAsync <R>(returnJson)));
            }

            return(new Tuple <HttpResponseMessage, R>(response, null));
        }
Exemplo n.º 2
0
        public async Task <IHttpResponse <TReturn> > PostAsync <T, TReturn>(string url, T data) where TReturn : class
        {
            HttpResponseMessage response = null;

            try
            {
                response = await _client.PostAsync(url, Json(await _json.SerializeAsync(data)));
            }
            catch (HttpRequestException)
            {
                return(new HttpResponse <TReturn>(null, null, true));
            }

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

                return(new HttpResponse <TReturn>(response, await _json.DeserializeAsync <TReturn>(content)));
            }

            return(new HttpResponse <TReturn>(response, null));
        }
Exemplo n.º 3
0
        public async Task SaveTokenAsync(JwtTokenDto tokenDto)
        {
            var data = await _json.SerializeAsync(tokenDto);

            await _localStorageManager.Set(TokenStorageKey, data);
        }