【问题标题】:415 Unsupported Media Type when using Postman and Asp Web Api使用 Postman 和 Asp Web Api 时出现 415 不支持的媒体类型
【发布时间】:2018-02-23 20:42:22
【问题描述】:

当我使用 Postman 创建新项目时,为什么会收到 415“不支持的媒体类型”状态。如果我使用 GetAll,我会得到想要的结果,但当我尝试创建某些东西时不会。代码如下:

[HttpPost]
public IActionResult Create([FromBody]TodoItem item)
{
    if (item == null)
    {
        return BadRequest();
    }
    _context.TodoItems.Add(item);
    _context.SaveChanges();

    return CreatedAtRoute("GetTodo", new { id = item.Id }, item);
}

【问题讨论】:

    标签: asp.net-core asp.net-core-webapi


    【解决方案1】:

    邮递员中的默认内容类型文本/纯文本尝试添加标题

    Content-Type:application/json 并且您正在使用 [FromBody] 标签,所以在正文中发送您的参数

    【讨论】:

      猜你喜欢
      • 2021-05-20
      • 2015-03-10
      • 2016-11-26
      • 2019-07-28
      • 2019-03-23
      • 2020-10-06
      • 1970-01-01
      • 2023-03-13
      • 2023-03-08
      相关资源
      最近更新 更多