[英]How to get request body data from System.Mvc.Web.ActionExecutingContext in c#
Here is my method It will take only one parameter .这是我的方法它只需要一个参数。 But I want user whaterver add in request body I need to save in logging.但我希望用户 whaterver 添加我需要保存在日志记录中的请求正文。
[HttpPost]
[LogAPIUser]
public async Task<JsonResult> GameDetail(long game)
Here is my Postman request这是我的邮递员请求
In ActionExecutingContext I have got only one action parameter在 ActionExecutingContext 我只有一个动作参数
How can I get all body request data?如何获取所有正文请求数据? If anyone have idea please let me know如果有人有想法请告诉我
Thanks in advance.提前致谢。
https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api states that: https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api指出:
At most one parameter is allowed to read from the message body.最多允许从消息体中读取一个参数。
The reason for this rule is that the request body might be stored in a non-buffered stream that can only be read once.此规则的原因是请求正文可能存储在只能读取一次的非缓冲流中。
You can try to look at this question: WebAPI Multiple Put/Post parameters你可以试试看这个问题: WebAPI Multiple Put/Post parameters
something in the effect of影响的东西
[HttpPost]
public string MyMethod([FromBody]JObject data)
{
long game = data["game"].ToObject<Long>();
long rer = data["rer"].ToObject<Long>();
}
(did not try code, might be buggy) (没有尝试代码,可能是错误的)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.