I am using a PHP API to return the data of a user and i am trying to get the result into an object.When i try to put it in a user object it just throws an exception at runtime.This is a WPF program that i was trying to get user data , which consists of username and password and a boolean which states if he logged in or not.
namespace WpfApp3 {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow: Window {
public MainWindow() {
InitializeComponent();
}
private async void show_selection(object sender, RoutedEventArgs e) {
var userName = username.Text;
var passWord = password.Text;
var formContent = new FormUrlEncodedContent(new [] {
new KeyValuePair < string, string > ("username", userName),
new KeyValuePair < string, string > ("password", passWord)
});
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.BaseAddress = new Uri("http://localhost/pharmasuite/login1.php");
var response = await client.PostAsync(client.BaseAddress.ToString(), formContent);
var user = await response.Content.ReadAsAsync < user > ();
if (user.logged_in == true) {
MessageBox.Show("logged in");
}
}
class user {
public string username {
get;
set;
}
public string password {
get;
set;
}
public bool logged_in {
get;
set;
}
}
}