Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

JSON Post request on button click

$
0
0

loginButton.Clicked += (object sender, EventArgs e) =>
{
Login(email.Text, password.Text);
};

On button Click this method is being called -

public void Login(string username, string password)
{
string url = "http://192.168.1.6:8080/doc_register";

        string contentType = "application/json";
        JObject oJsonObject = new JObject();

        oJsonObject.Add("name","myname");
        oJsonObject.Add("gender", "male");

        HttpClient oHttpClient = new HttpClient();
        var oTaskPostAsync = oHttpClient.PostAsync(url, new StringContent(oJsonObject.ToString(), Encoding.UTF8, contentType)).Result;

        if (oTaskPostAsync.IsSuccessStatusCode)
        {
            DisplayAlert("Account Created", "Head back to the hompage and login with your new account", "Ok");

        }
        else
        {
            DisplayAlert("Error Found", "", "Ok");
        }

I am not able to return response I am getting in return. How can I print the response? Or How to create a async method for calling POST method on button click.


Viewing all articles
Browse latest Browse all 204402


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>