【发布时间】:2015-08-13 04:07:34
【问题描述】:
我有一个名为广告的课程:
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 标头的错误?在您的 Postman 调用中添加适当的标头 Content-Type ,这应该可以解决它。
-
我的标题中有
Content-Type和Accept@DaveAgaba -
在下面查看我的答案。
标签: c# asp.net asp.net-web-api2 asp.net-identity