我在asp.net核心mvc中写了一个webhook,调用者发布了一些json.但Content-Type设置为application/vnd.myget.webhooks.v1+json.我只想把这个内容类型映射到JsonInputFormatter.
我这样做了,但想知道是否有更好的方法:
services.AddMvc( mvcConfig =>
{
var formatter = new JsonInputFormatter();
formatter.SupportedMediaTypes.Add(
new MediaTypeHeaderValue("application/vnd.myget.webhooks.v1+json") );
mvcConfig.InputFormatters.Add( formatter );
});
Run Code Online (Sandbox Code Playgroud)
您可以修改默认InputFormatter的ConfigureServices
services.Configure<MvcOptions>(options => {
options.InputFormatters.OfType<JsonInputFormatter>().First().SupportedMediaTypes.Add(
new MediaTypeHeaderValue("application/vnd.myget.webhooks.v1+json")
);
});
Run Code Online (Sandbox Code Playgroud)
......也许是略有改善
| 归档时间: |
|
| 查看次数: |
1869 次 |
| 最近记录: |