public async Task <string> Login(int id, string password) { var url = string.Concat(URL, "auth"); var uri = new Uri(string.Format(url, string.Empty)); var loginData = new { sspID = id, password = password }; var json = JsonConvert.SerializeObject(loginData); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = null; try { response = await HttpClient.PostAsync(uri, content); if (response.IsSuccessStatusCode) { var result = await response.Content.ReadAsStringAsync(); var token = JsonConvert.DeserializeObject <TokenDto>(result); HttpClientSingleton.SetAccessToken(token.Token); return(token.Token); } var error = "Error: Wrong ID or Password"; return(error); } catch (Exception ex) { var error = "Error: Connection timed out, Check your internet"; return(error); } }
public BaseService() { HttpClient = HttpClientSingleton.GetInstance(); }