convert a HttpResponseMessage to an object

Viewed 15359

I have this structure, I am using System.Net.Http and Newtonsoft as well. I need receive the webservice response and convert it in my class, but I don't know how to do that with a HttpResponseMessage and the posts that I've red hasn't helped me. It's a Xamarin.forms project.

 public static async Task<User> PostLoginAsync(string login, string senha)
    {
        using (var client = new HttpClient())
        {
            try
            {
                login = "email@hotmail.com";
                senha = "1111111";

                var content = new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair<string, string>("id", "1200"),
                        new KeyValuePair<string, string>("email", login),
                        new KeyValuePair<string, string>("password", senha),
                        new KeyValuePair<string, string>("json", "1"),
                     });

                HttpResponseMessage response = await client.PostAsync("http://ws.site.com", content);

                return null;
            }

            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return null;
            }
        }
    }

my class:

class User
{
    public string codigo { get; set; }
    public string nome { get; set; }
    public string email { get; set; }
    public string senha { get; set; }
    public string imagem { get; set; }
    public DateTime dataDeNasc { get; set;}
    public string cidade { get; set; }
    public string estado { get; set; }
    public string telefone { get; set; }
    public string sexo { get; set; }
}

If you can help me...I would appreciate that. Thank you anyways

1 Answers
Related