【发布时间】:2017-05-26 15:10:28
【问题描述】:
我正在使用 Postman 测试我的第一个 .net Core WebAPI
发生未知媒体类型错误。
我错过了什么?
这是我的发帖对象
public class Country
{
[Key]
public int CountryID { get; set; }
public string CountryName { get; set; }
public string CountryShortName { get; set; }
public string Description { get; set; }
}
这是 webapi 控制器
[HttpPost]
public async Task<IActionResult> PostCountry([FromBody] Country country)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_context.Country.Add(country);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (CountryExists(country.CountryID))
{
return new StatusCodeResult(StatusCodes.Status409Conflict);
}
else
{
throw;
}
}
return CreatedAtAction("GetCountry", new { id = country.CountryID }, country);
}
【问题讨论】:
-
您可以发布“标题”选项卡中的内容吗?尝试将 Content-Type 设置为 application/json
标签: rest asp.net-web-api2 asp.net-core-mvc postman