public async Task <TokenSessionRestResult> Register(UserPostBody userPostBody) { TokenSessionRestResult Result = new TokenSessionRestResult(); var uri = new Uri(Constants.register); var json = JsonConvert.SerializeObject(userPostBody); var postbody = new StringContent(json, Encoding.UTF8, "application/json"); try { var response = await _client.PostAsync(uri, postbody); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); Result = JsonConvert.DeserializeObject <TokenSessionRestResult>(content); MessagingCenter.Send(this, "Register", Result); } } catch (Exception ex) { Debug.WriteLine(@"\tERROR {0}", ex.Message); } return(Result); }
private async void GetToken() { TokenSessionRestResult Result = new TokenSessionRestResult(); var uri = new Uri(string.Format(Constants.get_token, Preferences.Get("sessionid", null))); try { var response = await _client.GetAsync(uri); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); Result = JsonConvert.DeserializeObject <TokenSessionRestResult>(content); Preferences.Set("token", Result.token); } } catch (Exception ex) { Debug.WriteLine(@"\tERROR {0}", ex.Message); } }