public ActionResult Index()
{
HttpClient client = new HttpClient();
string dateNowJson = "{\"dateNow\":\"" + DateTime.Now.ToString() + "\"}";
HttpContent httpcontent = new StringContent(dateNowJson, System.Text.Encoding.UTF8, "application/json");
HttpResponseMessage response = client.PostAsync("http://localhost:10446//api/DriTrainSelect", httpcontent).Result;
if (response.IsSuccessStatusCode)
{
string json = response.Content.ReadAsStringAsync().Result;
ResponseModel<List<DriverTrained>> resp = JsonConvert.DeserializeObject<ResponseModel<List<DriverTrained>>>(json);
ViewData["driverTrainList"] = resp.Data;
}
else
{
ViewData["driverTrainList"] = null;
}
return View();
}
c# 调用webApi
最新推荐文章于 2025-06-08 11:15:39 发布