【发布时间】:2019-05-09 11:26:09
【问题描述】:
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/nvl1G.png
[Route("api/values")]
[ApiController]
public class ValuesController : ControllerBase
{
[Route("asd")]
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}
[Route("Test")]
[HttpPost]
public IActionResult Test([FromBody] Person p)
{
return Ok(p);
}
}
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
}
我正在为 web api 使用 asp.net 核心。目前正在做测试。正在使用邮递员将 json 对象发布到 web api。但我无法得到对象。 下面是web api返回的消息
{
"errors": {
"": [
"A non-empty request body is required."
]
} ,
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "80000099-0007-fd00-b63f-84710c7967bb"
}
【问题讨论】:
-
您在请求中的路线是“人”,但在代码中是“测试”???
标签: c# json post asp.net-core