public async Task <string> storeReadings(int sId, double value) { webClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", client.token); uri = new Uri(baseAddress, "readings"); Readings read = new Readings() { sensor_id = sId, value = value }; var json = JsonConvert.SerializeObject(read); var content = new StringContent(json, Encoding.UTF8, "application/json"); try { var response = await webClient.PostAsync(uri, content); //var rString = await response.Content.ReadAsStringAsync(); //if (response.IsSuccessStatusCode) //{ // read = JsonConvert.DeserializeObject<Readings>(rString); // Debug.WriteLine("Dato almacenado coorectamente!"); // return rString; //} } catch (Exception ex) { return(ex.Message); } return(null); }
public async Task <Readings> getReadingInfo(int readingID) { webClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", client.token); try { var response = await webClient.GetAsync("readings/" + readingID); var rString = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { Readings r = new Readings(); r = JsonConvert.DeserializeObject <Readings>(rString); return(r); } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } return(null); }