У меня есть класс, который зовут Реклама:Нет MediaTypeFormatter доступен для чтения объект типа «Реклама» в asp.net Web API
public class Advertisement
{
public string Title { get; set; }
public string Desc { get; set; }
}
и в моем контроллере:
public class OrderController : ApiController
{
public UserManager<IdentityUser> UserManager { get; private set; }
// Post api/Order/Test
[Route("Test")]
public IHttpActionResult Test(Advertisement advertisement)
{
var currentUser = User.Identity.GetUserId();
Task<IdentityUser> user = UserManager.FindByIdAsync(currentUser);
return Ok(User.Identity.GetUserId());
}
но когда я тестирую его с Postman, я сталкиваюсь с этой ошибкой,
"Message": "The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource.",
"ExceptionMessage": "No MediaTypeFormatter is available to read an object of type 'Advertisement' from content with media type 'application/octet-stream'.",
"ExceptionType": "System.Net.Http.UnsupportedMediaTypeException",
"StackTrace": " at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)"
Может ли AnyBody помочь мне?
Из ошибки появляется я, что у вас нет заголовка Content-Type? Добавьте соответствующий заголовок Content-Type в свой почтовый вызов, и он должен его исправить. –
У меня есть 'Content-Type' и' Accept' в моих заголовках @DaveAgaba –
Посмотрите мой ответ ниже. –