public async static Task <string> CheckToken() { string token = await FileHandle.GetToken(); string response = await Call(APITypes.GetInfo, default(T)); try { Response resp = JsonConvert.DeserializeObject <Response>(response); if (resp.token != null) { return("true"); } return(null); } catch { return(null); } }
public async static Task <string> Call(APITypes type, T item) { string URL = APIExtensions.getURL(type); HttpClient httpClient = new HttpClient(); if (APIExtensions.isTokenNeeded(type)) { httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + await FileHandle.GetToken()); } if (item == null) { string content = await httpClient.GetAsync(URL).Result.Content.ReadAsStringAsync(); Debug.WriteLine("GET: " + content); return(content); // HTTP GET } try { string data = JsonConvert.SerializeObject(item); string content = await httpClient.PostAsync(URL, new StringContent(data, System.Text.Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync(); Debug.WriteLine("POST: " + content); return(content); } catch (JsonSerializationException) { ExceptionHandle.ThrowDebug("json error"); return(null); } }