415 JSON HttpPost上的不支持的媒体类型错误

时间:2016-12-13 01:33:19

标签: c# json asp.net-core http-post fiddler

我使用ASP.NET Core使用以下代码控制器 -

namespace WebApplication.Controllers
{
    [Route("api/[controller]")]
    public class TodoController : ControllerBase
    {
        [HttpPost]
        public List<Testing> Create([FromBody] List<Testing> item)
        {
            return item;
        }
    }
}

当我尝试使用fiddler -

执行以下HTTP发布时
POST - http://localhost:30001/api/todo
Content-Type: application/json; charset=utf-8
Host: localhost:30001
Content-Length: 117

[{"Name":"Item1","LastName":"Test1"}, {"Name":"Item2","LastName":"Test2"}, {"Name":"Item3","LastName":"Test3"}]

我最终得到了415 Unsupported Media Type异常。如果我从POST请求中的参数中删除[FromBody]属性为null。如何修复绑定?

0 个答案:

没有答案