[英]ASP.NET Web API multiple post messages single controller or action
So I have the following issue: 所以我有以下问题:
We have a scenario where a third party is sending post messages to our server, we have no control over that, and they want to send everything to a single url, so we can not do anything regarding query parameters, so my question then is, is it possible to handle different post messages with a single action. 我们有一个场景,第三方正在向我们的服务器发送帖子消息,我们无法控制它,他们想将所有内容发送到一个网址,所以我们无法对查询参数做任何事情,所以我的问题是,是否可以通过单个操作处理不同的帖子消息。 In essence the content of the post message will define what needs to happen with said request.
本质上,帖子消息的内容将定义所述请求需要发生的事情。
Post message 1: 发布消息1:
<xml>
<content1> content </content1>
<content2> content </content2>
</xml>
Post message 2: 发布消息2:
<xml>
<content1> content </content1>
<content3> content </content3>
</xml>
As you can see some of the messages will have similar properties. 如您所见,某些消息将具有类似的属性。
Thanks 谢谢
You can use the following signature to accept arbitrary XML content, 您可以使用以下签名来接受任意XML内容,
public HttpResponseMessage Post([FromBody]XElement xmlbody) {
// Process the xmlbody
return new HttpResponseMessage(HttpStatusCode.Created);
}
I have more details about this kind of raw media type processing here . 我对这种原始媒体类型处理的更多细节在这里 。
It is possible. 有可能的。 Specify your action to have a string input parametre.
指定您的操作以使字符串输入参数。 That way you can get the entire message as a string and not worry about its properties... However, you will need to implement the logic in the controller to diferentiate messages.
这样,您可以将整个消息作为字符串获取,而不用担心其属性......但是,您需要在控制器中实现逻辑以区分消息。
[HttpPost]
public ActionResult MyActionForAllMessages(string message)
{
//Your logic
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.