public Georreferencia GeoGet(int?filter) { var url = $"https://localhost:44317/api/Georreferencias/" + filter; var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; request.ContentType = "application/json"; request.Accept = "application/json"; Georreferencia atri = new Georreferencia(); string json = ""; try { using (WebResponse response = request.GetResponse()) { using (Stream strReader = response.GetResponseStream()) { //if (strReader == null) return; using (StreamReader objReader = new StreamReader(strReader)) { string responseBody = objReader.ReadToEnd(); // Do something with responseBody json = responseBody; atri = new JavaScriptSerializer().Deserialize <Georreferencia>(json); Session["referencia"] = atri; } } } return(atri); } catch (WebException ex) { return(atri); } }
public async Task <JsonResult> insertGeoReAsync(Models.Georreferencia atri) { try { var payload = new Georreferencia { idEstado = atri.idEstado, Latitud = atri.Latitud, Longitud = atri.Longitud, }; var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(payload)); var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json"); using (var httpClient = new HttpClient()) { var httpResponse = await httpClient.PostAsync("https://localhost:44317/api/Georreferencias", httpContent); if (httpResponse.Content != null) { var responseContent = await httpResponse.Content.ReadAsStringAsync(); return(Json(new { status = true, message = "Exito" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { status = false, message = "Aldo salio mal" }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { return(Json(new { status = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } }