Api Rest Xamarin forms c #

0

I have my api rest created in lumen (PHP) and it is in my MySQL hosting, I have my users table with the fields ID, DNI, Name, Position, updated_at and created_at, when I insert by POSTMAN I get it right (obviously only I put DNI, Name and Position since the rest is generated automatically). The problem is in my VS that when I send it to make the insert I get the following error.

* THIS IS MY CODE IN C # *

THIS IS MY CLASS:

public class Usuarios
{
    public int UsuarioID { get; set; }
    public string DNI { get; set; }
    public string Nombres { get; set; }        
    public string Cargo { get; set; }      
}

THIS IS MY REST SERVICE:

HttpClient client2 = new HttpClient();
    public async Task<int> AddTodoItemAsync(Usuarios usuarios)
    {
        var data = JsonConvert.SerializeObject(usuarios);
        var content = new StringContent(data, Encoding.UTF8, "application/json");
        var response = await client2.PostAsync("http://www.xxxxxxx.com/public/api/userNew", content);
        var result = JsonConvert.DeserializeObject<int>(response.Content.ReadAsStringAsync().Result);
        return result;
    }

EVENT CLICK ON MY BUTTON TO GIVE "REGISTER"

RestService dataService;
async void btn_NewUser(object sender, System.EventArgs e)
    {
        if (string.IsNullOrEmpty(txtdni.Text) || string.IsNullOrEmpty(txtnombres.Text) || string.IsNullOrEmpty(txtcargo.Text))
        {
            await DisplayAlert("Atencion","POR FAVOR LLENAR TODOS LOS CAMPOS","Ok");
        }
        else
        {
            Usuarios newUser = new Usuarios
            {
                DNI = txtdni.Text.Trim(),
                Nombres = txtnombres.Text.Trim(),
                Cargo = txtcargo.Text.Trim()                   
            };
            await dataService.AddTodoItemAsync(newUser);
        }
    
asked by Luis Vega 15.02.2018 в 00:25
source

0 answers