视图控制器后台代码
- public ActionResult Index()
- {
- var requestJson = JsonConvert.SerializeObject("[{'CityId':18,'CityName':'西安','ProvinceId':27,'CityOrder':1},{'CityId':53,'CityName':'广州','ProvinceId':27,'CityOrder':1}]");
- HttpContent httpContent = new StringContent(requestJson);
- httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
- var httpClient = new HttpClient();
- var responseJson = httpClient.PostAsync("http://localhost:6972/api/test/Post/", httpContent)
- .Result.Content.ReadAsStringAsync().Result;
- ViewBag.s = responseJson;
- return View();
- }
API控制器后台代码
- // POST api/values
- public HttpResponseMessage Post([FromBody]string value)
- {
- return Request.CreateResponse(HttpStatusCode.OK, value);
- }