我在提取请求和响应数据时遇到问题。我尝试下面的代码,它工作正常。只想知道是否有更好的方法可以在动作过滤器webapi中获取请求和响应数据。
public override void OnActionExecuted(HttpActionContext actionContext)
{
string Request;
using (var stream = new StreamReader(actionContext.Request.Content.ReadAsStreamAsync().Result))
{
stream.BaseStream.Position = 0;
Request = stream.ReadToEnd();
}
}
public override void OnActionExecuting(HttpActionContext filterContext)
{
string Request;
using (var ms = new MemoryStream())
{
var stream = new StreamReader(filterContext.Request.Content.ReadAsStreamAsync().Result);
stream.BaseStream.Position = 0;
Request = stream.ReadToEnd();
}
}