我是使用ASP.net的新手。我对POST请求有问题。也许我的代码是错误的,我找不到哪里!
邮递员在尝试邮寄请求时向我发送错误消息:
“ ExceptionType”:“ System.Net.Http.UnsupportedMediaTypeException”,“ StackTrace”:“àSystem.Net.Http.HttpContentExtensions.ReadAsAsync [T](HttpContent内容,类型,IEnumerable1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n à System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable
1格式化程序,IFormatterLogger formatterLogger ,CancellationToken cancellingToken)“}
这是我的代码:
// POST: api/Boooks
[Route("~/api/PostCreate")]
public IHttpActionResult Post([FromBody] Books books)
{
if (!ModelState.IsValid)
return BadRequest("Invalid data.");