首页 > 代码库 > HttpResponseMessage 调用.net web api

HttpResponseMessage 调用.net web api

     //
        // GET: /Home/
        //释迦苦僧 
        public ActionResult Index()
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("http://localhost:12899/");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = client.GetAsync("api/task").Result;
            if (response.IsSuccessStatusCode)
            {
                var tasks = response.Content.ReadAsStringAsync();
                List<TaskInfoModel> p = JsonConvert.DeserializeObject<List<TaskInfoModel>>(tasks.Result);
                Console.Write(tasks.Result);
            }
            return View();
        }

 

HttpResponseMessage 调用.net web api