I already figured out how to post data on the web api, but the data is not posting, i know that the codes are right but the conversion of text might be wrong (Correct me if I'm wrong)-
This is my Main Acticity
using Android.App;
using Android.Widget;
using Android.OS;
using System;
using System.Net.Http;
using Newtonsoft.Json;
using System.Text;
namespace PostRequest
{
[Activity(Label = "PostRequest", MainLauncher = true)]
public class MainActivity : Activity
{
Button savebtn;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
savebtn = FindViewById<Button>(Resource.Id.click_meh);
savebtn.Click += async delegate
{
using (var client = new HttpClient())
{
//new post
var post = new visitorsmodel
{
ID = 1,
lname = "Square Pants",
fname = "Sponge",
mname = "Arenas",
school = "BOB",
email = "spoongebob@gmail.com",
num = "0909090909"
};
// create the request content and define Json
var json = JsonConvert.SerializeObject(post);
var content = new StringContent(json, Encoding.UTF8, "application/json");
// send a POST request
var uri = "http://192.168.1.140:9090/";
var results = await client.PostAsync(uri, content);
//Error
results.EnsureSuccessStatusCode();
////Getting results
//var resultsString = await results.Content.ReadAsStringAsync();
//var display = JsonConvert.DeserializeObject<info>(resultsString);
}
};
}
}
}
When i click the "CLICK MEH" button, the data will post on the Web API (As i know)
and here is my class model:
namespace PostRequest
{
public class visitorsmodel
{
public int ID { get; set; }
public string lname { get; set; }
public string fname { get; set; }
public string mname { get; set; }
public string school { get; set; }
public string email { get; set; }
public string num { get; set; }
public override string ToString()
{
return string.Format(
"Post ID: {0}\nlname: {1}\nfname: {2}mname: {3}school: {4}email: {5}num:",
ID, lname, fname, mname, school, email, num);
}
}
}
**But there's no changes in the Web API that i create using WPF self host.
This is my WEB API**
why i can't post in this web API (XML)?
Thanks in advance