public static string Login(LoginModel model) { string result = string.Empty; using (var client = new HttpClient()) { client.BaseAddress =new Uri(webAPIURL); // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); // List data response. HttpResponseMessage response = client.PostAsJsonAsync("/Services/AuthenticationService/Login",model).Result; // Blocking call! if (response.IsSuccessStatusCode) { // Parse the response body. Blocking! var dataObjects = response.Content.ReadAsAsync<IEnumerable<DataObject>>().Result; foreach (var d in dataObjects) { result = string.Format("{0}", d.Name); } } else { result = string.Format("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } return result; }
// GET api/<controller> public string Get(LoginModel model) { return AuthenticationService.Login(model); }