コード例 #1
0
        public async Task <String> CrearTareo(TareoPersonalApi entidad)
        {
            String codigoMovimientoEspecial = String.Empty;

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var informacionAMandar = Newtonsoft.Json.JsonConvert.SerializeObject(entidad,
                                                                                         Newtonsoft.Json.Formatting.None,
                                                                                         new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    });

                    client.BaseAddress = new Uri(urlapiTareo);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                    client.Timeout = TimeSpan.FromMinutes(10);


                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "")
                    {
                        Content = new StringContent(informacionAMandar, Encoding.UTF8, "application/json")
                    };
                    HttpResponseMessage response = await client.SendAsync(request);

                    if (response.IsSuccessStatusCode)
                    {
                        var jsonPuro = await response.Content.ReadAsStringAsync();

                        var jsonDesarializado = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonPuro);

                        codigoMovimientoEspecial = jsonDesarializado.ToString();
                    }
                }

                return(codigoMovimientoEspecial);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #2
0
        //public async Task PostJsonHttpClient(object content, CancellationToken cancellationToken)
        public async Task PostJsonHttpClient(string ID_TAREADOR, string ID_PERSONAL, string PERSONAL, string ID_PROYECTO,
                                             string ID_SITUACION, string ID_CLASE_TRABAJADOR, DateTime FECHA_TAREO, string TIPO_MARCACION, string HORA,
                                             DateTime FECHA_REGISTRO)
        {
            try
            {
                TareoPersonalApi varTareo = new TareoPersonalApi
                {
                    ID                  = 1,
                    ID_TAREADOR         = ID_TAREADOR,
                    ID_PERSONAL         = Convert.ToInt32(ID_PERSONAL),
                    PERSONAL            = PERSONAL,
                    ID_PROYECTO         = ID_PROYECTO,
                    ID_SITUACION        = Convert.ToInt32(ID_SITUACION),
                    ID_CLASE_TRABAJADOR = Convert.ToInt32(ID_CLASE_TRABAJADOR),
                    FECHA_TAREO         = FECHA_TAREO,
                    TIPO_MARCACION      = Convert.ToInt32(TIPO_MARCACION),
                    HORA                = HORA,
                    FECHA_REGISTRO      = FECHA_REGISTRO,
                    SINCRONIZADO        = 0,
                    FECHA_SINCRONIZADO  = DateTime.Now.Date,
                    TOKEN               = App.Token
                };

                var         httpClient  = new HttpClient();
                var         json        = JsonConvert.SerializeObject(varTareo);
                HttpContent httpContent = new StringContent(json);
                httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                HttpResponseMessage response = await httpClient.PostAsync(urlapiTareo, httpContent).ConfigureAwait(false);

                string respuesta   = response.RequestMessage.ToString();
                string status_code = response.StatusCode.ToString();
            }
            catch (Exception)
            {
                throw;
            }
        }