415不支持的媒体类型asp.net核心 [英] 415 Unsupported Media Type asp.net core

查看:70
本文介绍了415不支持的媒体类型asp.net核心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件从Postman发布到我创建的端点.但这给了我这个错误.我没有在邮递员中传递标头Content-Type

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不支持的媒体类型

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;
    }
}

课程

public class Entity 
{
    public List<IFormFile> Files { get; set; }
}

推荐答案

如果要发布,请尝试使用 [FromForm] 代替 [FromBody] 作为方法参数表单数据.

Try using [FromForm] instead of [FromBody] for the method parameter if you're POSTing form data.

这篇关于415不支持的媒体类型asp.net核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆