WebAPI multipart / form-data模型绑定

时间:2018-06-05 16:04:49

标签: asp.net-web-api multipartform-data

我需要为某些Web服务实现webhook API端点,以便使用某些数据请求它们。当我看到请求的内容类型(我无法访问的Web服务)是multipart/form-data时,问题就出现了。我希望它是application/json,但没有什么是完美的,对吗?

我想要做的是将传入请求中的数据绑定到我的自定义模型。 我的模型看起来像这样:

public class DroppedViewModel
{
    public string Reason { get; set; }

    public string Recipient { get; set; }

    public string Code { get; set; }

    public string Description { get; set; }
}

我希望我的WebApi操作看起来像这样:

[HttpPost]
public HttpResponseMessage Dropped(DroppedViewModel model)
{
    // do something with my model
}

我不想在整个应用程序中添加对multipart/form-data的支持,只是在一个控制器上执行少量操作(可能某些ActionFilterAttribute的实现可以解决这个问题?或者可能是自定义模型绑定程序?)

我没有找到任何适合我的解决方案,或者至少我不需要手动解析数据。

我再次对我的端点请求的外观没有看法,但我知道表单数据中包含的某些键值对的关键名称,我不会从Web服务接收任何文件,只是表单数据

0 个答案:

没有答案
相关问题