解析成功:
3、【Post】请求【API】解析
编写解析过程(HomeController.cs):
//客户端请求 HttpClient http = new HttpClient(); var str = "";//请求数据。这里为空 HttpContent content = new StringContent(str); //请求地址 string url = "http://localhost:5833/api/Test/GetPostInfo"; Task<HttpResponseMessage> postTask = http.PostAsync(url,content); HttpResponseMessage result = postTask.Result;//拿到网络请求结果 result.EnsureSuccessStatusCode();//抛出异常 Task<string> task = result.Content.ReadAsStringAsync();//异步读取数据 //发送值前台 ViewBag.ResultTyle = JsonConvert.DeserializeObject<ResultType>(task.Result);
编码位置:
请求效果: