Help I can't get a user's data when I log in

faraon16faraon16 Member ✭✭
edited January 13 in Xamarin.Forms

I am using MVVM and in my login VIewModel I have done the GetUser part and in an ApiService class I have the service
Then I must receive the data when I send the TOKEN that I generate when I log in
and TOKEN I receive it well but it does not generate user data
User comes out null
this is my MVVM
User user = new User();
user = await apiService.GetUser(
"URLBASE",
"/api",
"/datosUsuario",
response.token);

This is mi ApiService

public async Task<User> GetUser(
        string urlBase,
        string servicePrefix,
        string controller,
        string Token)
    {
        try
        {
            var model = new UserRequest
            {
                token = Token
            };
            User user = new User();
            var diccionario = new List<KeyValuePair<string, string>>();
            diccionario.Add(new KeyValuePair<string, string>("token", Token));
            var cliente = new HttpClient();
            cliente.BaseAddress = new Uri(urlBase);
            var url = string.Format("{0}{1}{2}", cliente.BaseAddress, servicePrefix, controller);
            var req = new HttpRequestMessage(HttpMethod.Post, url)
            { Content = new FormUrlEncodedContent(diccionario) };
            var response = await cliente.SendAsync(req);
            if (!response.IsSuccessStatusCode)
    {
                  return null;
            }
            var result = await response.Content.ReadAsStringAsync();
            user = JsonConvert.DeserializeObject<User>(result);
            return new User
            {


            };

        }
        catch 
        {
            return null;
        }
    }
Tagged:
Sign In or Register to comment.