Aru*_*E S 12 rest asp.net-web-api2 postman asp.net-core-mvc
我正在使用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; }
}
Run Code Online (Sandbox Code Playgroud)
这是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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9542 次 |
| 最近记录: |