从HttpActionContext获取JSON内容
我正在尝试从HttpActionContext获取JSON内容 我想我能做到:从HttpActionContext获取JSON内容,json,asp.net-web-api,asp.net-web-api2,Json,Asp.net Web Api,Asp.net Web Api2,我正在尝试从HttpActionContext获取JSON内容 我想我能做到: public override void OnActionExecuting(HttpActionContext actionContext) { var test = request.Content.ReadAsStringAsync().Result; var test2 = actionContext.ControllerContext.Request.Content.ReadAsStrin
public override void OnActionExecuting(HttpActionContext actionContext)
{
var test = request.Content.ReadAsStringAsync().Result;
var test2 = actionContext.ControllerContext.Request.Content.ReadAsStringAsync().Result;
但这些都不管用。我的测试变量总是空的,即使我在POST请求中传递JSON内容。有人能给我解释一下我是如何得到我想要的吗?你能分享一下你的想法吗?我看到您正在尝试在模型绑定发生后读取内容…ModelBinding读取请求流以将数据绑定到模型,因此流的位置可能位于末尾…您需要显式地将位置设置回开始以获取原始内容…我想将JSON内容保存到我们的数据库中,以便记录目的。我该如何将位置设置回起始位置?这可能正是我想要的。