控制器中的多个POST方法 [英] Multiple POST method in a controller

查看:171
本文介绍了控制器中的多个POST方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的.net核心web api应用程序需要多个POST方法。



从请求体中捕获xml的第一个动作

Need to have multiple POST method in my .net core web api application.

First action to capture xml from request body

Quote:

[HttpPost]

[Consumes(application / xml)]

public void IngestXML([FromBody] XElement xmlInput)

{..}

[HttpPost]
[Consumes("application/xml")]
public void IngestXML([FromBody]XElement xmlInput)
{..}





从请求正文中捕获json的第二个动作



second action to capture json from request body

Quote:

[HttpPost]]

[Consumes(application / json)]

public void IngestJson([FromBody] JToken jsonInput)

{...}

[HttpPost)]
[Consumes("application/json")]
public void IngestJson([FromBody]JToken jsonInput)
{...}







问题:是否有可能路由基于查询字符串值?

例如../home/index?format=xml到第一个操作方法

../home/index?format=json第二种行动方式



我尝试过:



我尝试过具有不同的路由如下



...主页/ index / xml

...主页/ index / json



但我正在寻找基于查询字符串值的地图/路线解决方案




Question: Is it possible to route based on query string value?
for example, ../home/index?format=xml to first action method
../home/index?format=json to second action method

What I have tried:

I tried with different routing as below

...Home/index/xml
...Home/index/json

But I am looking for solution to map/route based on query string value

推荐答案

您可以使用[Route]或[ActionName] ...

ASP.NET Web API中的路由Microsoft Docs [ ^ ]

ASP.NET Web API 2中的属性路由Microsoft Docs [ ^ ]
You can use either [Route] or [ActionName]...
Routing in ASP.NET Web API | Microsoft Docs[^]
Attribute Routing in ASP.NET Web API 2 | Microsoft Docs[^]


这篇关于控制器中的多个POST方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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