public async System.Threading.Tasks.Task armarAsync(int uno, int dos, string tres, string cuatro, string MacAddress1, string macRouter) { geo _geo = new geo(); Position _position = await _geo.GetPosition(); MiPing iping = manejador.getPing(); Datos datos = new Datos() { lat = (Double)_position.Latitude, lng = (Double)_position.Longitude, RTT = iping.RTTdeMiPing, status = iping.status, address = iping.Address, jitter = calculate.getJitter(iping.RTTdeMiPing), lantency = calculate.getLatency(iping.RTTdeMiPing), LinkSpeed = uno, SignLevel = dos, ssid = tres, DefaultGate = cuatro, MacAddress = MacAddress1, mail = Settings.email, pass = Settings.pass, MacDelRouter = macRouter, }; string x = envia.sendJson(datos); changer changer = new changer(); changer.changerStatus(x); }
public string sendJson(Datos datos) { changer status = new changer(); var result = ""; try { var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://192.168.0.99" + "/api/data/data_gather"); //Settings.url + " /api/data/data_gather"); httpWebRequest.ContentType = "application/json"; //tipo de archivo que contiene o MIME httpWebRequest.Method = "POST"; //METODO httpWebRequest.Timeout = 10000; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = JsonConvert.SerializeObject(datos); streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } HttpWebResponse myResponse = (HttpWebResponse)httpWebRequest.GetResponse(); if (myResponse.StatusCode == HttpStatusCode.OK) { var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { result = streamReader.ReadToEnd(); } } status.changerStatus(myResponse.StatusDescription); myResponse.Close(); if (result != null) { Console.WriteLine("envie un json"); Console.WriteLine("resultado es " + result.ToString()); } else { Console.WriteLine("resultado es " + result.ToString()); } } catch (WebException ex) { var response = ex.Response as HttpWebResponse; if (response == null) { throw; } return(response.StatusCode.ToString()); } return(result); }