Anele Ngqandu

Anele Ngqandu

  • 1k
  • 429
  • 28.1k

Postasync works with UWP but breaks on android project

May 15 2017 10:35 AM
Hi

Been having issue with Xamarin Cross Platform Android Project. I am using Wep Api Project to call a service from xamarin portable project.
 
  1. //Portable project  
  2. var auth = new SigninModel  
  3.             {  
  4.                 Username = username,  
  5.                 Password = password  
  6.    
  7.             };  
  8.   
  9.   
  10.   
  11. var stringContent = new StringContent(JsonConvert.SerializeObject(auth), Encoding.UTF8, "application/json");  
  12.             var response = await Client.PostAsync("http://localhost:54019/api/AuthenticationApi/Login", stringContent);  
  13.   
  14.   
  15. //WebApi   
  16.         [System.Web.Http.Route("api/AuthenticationApi/Login/")]  
  17.         [System.Web.Http.AcceptVerbs("GET""POST")]  
  18.         [System.Web.Http.HttpPut]  
  19.         public DBResult Login(AuthenticationModel model)  
  20.         {  
  21.             SupervisorModel result = null;  
  22.             bool hasError = false;  
  23.             string errorText = "";  
  24.    
  25.             if (ModelState.IsValid)  
  26.             {  
  27.                 result = Authentication.AuthenticateUser(model.Username, model.Password);  
  28.    
  29.             }  
  30.             else  
  31.             {  
  32.                 hasError = true;  
  33.    
  34.             }  
  35.    
  36.             return new DBResult { status = !hasError ? "Success" : "Fail", descripText = BadRequest(ModelState).ToString(), data = new SupervisorModel { Id = result.Id, Name = result.Name, Surname = result.Surname } };  
  37.    
  38.         }  
 

Answers (1)