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)); }
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)); }
public async Task SaveTokenAsync(JwtTokenDto tokenDto) { var data = await _json.SerializeAsync(tokenDto); await _localStorageManager.Set(TokenStorageKey, data); }