Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

Problem in consuming restful webservice by post method.

$
0
0

Hi, I am very new with webservices. I need to create login by webservice. I am providing userid and password and the webservice will return login validation. The webservice is returning null response. Here is my code-
On button click -

btnGo.Clicked += async (sender, args) =>
{
var sv = new LoginWebservice();
var usr = await sv.GetUserAsync();
Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
{
msg.Text = "found " + usr.Length ;
});
Content = layout;
}

Class for webservice-
public class LoginWebservice
{
public LoginWebservice() { }

    public async Task<LoginUser[]> GetUserAsync()
    {

            var client = new System.Net.Http.HttpClient();
            client.BaseAddress = new Uri("http://developer-platform.com/dutyfreebuzz/web_services/Login");
            StringContent str = new StringContent("username=admin&password=12345", Encoding.UTF8, "application/x-www-form-urlencoded");
            var response = await client.PostAsync(new Uri("http://developer-platform.com/dutyfreebuzz/web_services/Login/loginJSON"), str);
            var loginJson = response.Content.ReadAsStringAsync().Result;
            Rootobject rootobject = new Rootobject();
            if (loginJson != "")
            {
                rootobject = JsonConvert.DeserializeObject<Rootobject>(loginJson);
            }
            return rootobject.loginusers;

    }

}

Well the webservice is suppose to return - {"success":false,"message":"Entered wrong email or password"} for wrong credential. But var response is returning null. Can anyone please help me with this.

Thanks


Viewing all articles
Browse latest Browse all 75885

Trending Articles



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