作者:孙亦然5277 | 来源:互联网 | 2023-05-19 14:53
视图控制器后台代码
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);
}
经过实测,是好用的!