public void PostTowardUrl(IncidenciaPost obj) { var client = new RestClient("http://192.168.0.100:44346/api/incidencia/post-incidencia"); var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json; charset=utf-8"); request.AddHeader("server", "Microsoft-IIS/10.0"); request.AddJsonBody(obj); IRestResponse response = client.Execute(request); }
public async Task <bool> RegistrarNuevaIncidenciaAsync(IncidenciaPost incidencia) { try { var json = JsonConvert.SerializeObject(incidencia); var stringContent = new StringContent( json, System.Text.Encoding.UTF8, "application/json" ); var response = await Instance.PostAsync("incidencia/post-incidencia", stringContent); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); var httpResult = JsonConvert.DeserializeObject <HttpResult <bool> >(content); if (httpResult.ErrorCode == ResponseCode.Ok) { return(true); } else { throw new Exception(httpResult.ErrorMessage); } } else { throw new Exception(response.ReasonPhrase); } } catch (Exception e) { throw new Exception(e.Message); } }