415 Unsupported Media Type asp.net core

混江龙づ霸主 提交于 2021-02-16 15:48:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!