Forum General

How call web api service


I have the following method in my web api:

public string ValidarLogin(LoginViewModel usuario) {
return string.Format(usuario.Name+'-'+usuario.pass);

But I want to call this method in my app I have the following message error : Internal server Error...

The code is

using (var Cliente = new HttpClient())

                var json = JsonConvert.SerializeObject(login);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                //  send a POST request  
                var result = await Cliente.PostAsync(Url, content);

                // on error throw a exception  

                // handling the answer  
                var response = await result.Content.ReadAsStringAsync();
                var post = JsonConvert.DeserializeObject<LoginViewModel>(response);


Any one have any idea that is the error? thanks, advance


  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    The called web service has to have a post-controller (method) and you have to post the content as the method is waiting for. You don't have posted your "url" and the object login.
    Internal server error normally means, that the data you pass don't match the awaited data or something similar.

Sign In or Register to comment.