1,配置路由
在 Startup 类下的 Configure 函数下添加
app.UseMvc(routes=>
{
routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}");
});
3,
[HttpPost]
public IActionResult Index()
{
HttpContext.Response.ContentType = "application/json";
string json = "";
using (var sr = new StreamReader(Request.Body,Encoding.UTF8))
{
var v =sr.ReadToEndAsync();//或者sr.ReadToEnd()
v.Wait();
json = v.Result;
}
return Content(json);
}
本文介绍如何在ASP.NET Core中配置路由,并通过HttpPost方法处理JSON请求。具体包括在Startup类下的Configure函数中设置默认路由,以及如何读取并响应JSON格式的数据。
1302





