问题
Detail
I am trying to post a file from Postman to the endpoint I have created. but it gives me this error. I am not passing the header Content-Type in postman
415 Unsupported Media Type
API
[Consumes("multipart/form-data")]
[HttpPost]
public async Task<IActionResult> SendEmail([FromBody]Entity entity)
{
try
{
return OK();
}
catch (Exception e)
{
throw e;
}
}
Class
public class Entity
{
public List<IFormFile> Files { get; set; }
}
回答1:
Try using [FromForm]
instead of [FromBody]
for the method parameter if you're POSTing form data.
回答2:
In Postman, when creating a POST request, the default is "Text". Change it to JSON.
回答3:
In Postman, after ensuring that you're using raw and its in JSON format. Most especially when making GET request and you're not sending any data in the body of the request ensure that the body of the request is not empty. It must have an empty object: { }
来源:https://stackoverflow.com/questions/49228906/415-unsupported-media-type-asp-net-core