示例#1
0
        private void iconButton1_Click(object sender, EventArgs e)
        {
            try
            {
                string nombre, apellido, puesto;
                nombre   = textBox1.Text;
                apellido = textBox2.Text;
                puesto   = comboBox1.SelectedItem.ToString();

                JSON.Trabajador trabajador = new JSON.Trabajador();
                JSON.Api        api        = new JSON.Api();
                JSON.Curl       curl       = new JSON.Curl();

                trabajador.Nombre   = nombre;
                trabajador.Apellido = apellido;
                trabajador.Puesto   = puesto;

                curl.verbo = Method.POST;
                curl.json  = trabajador;

                MessageBox.Show(api.apicall(curl));
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("ALGO SALIO MUY MUY MUUUY MAAAL :(");
            }
        }
示例#2
0
        public string apicall(Curl datos)
        {
            var cliente = new RestClient(datos.url);
            var request = new RestRequest(datos.verbo);

            request.AddHeader("Content-Type", "Application/Json");
            string json = JsonSerializer.Serialize(datos.json);

            request.AddJsonBody(json);
            //Console.WriteLine(json);
            IRestResponse response = cliente.Execute(request);

            return(response.Content);
        }