zoukankan      html  css  js  c++  java
  • 当 method =post时,读取inputStream到RequestBody

            /// <summary>
            /// 当 method =post时,读取inputStream到RequestBody
            /// </summary>
            /// <param name="filterContext"></param>
            protected override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                if (!this.ModelState.IsValid) {
                    filterContext.Result = Json(new 
                    {
                        message = ModelStateHelper.GetModelErrorMessages(ModelState), 
                        code = ResponseCode.错误请求 
                    });
                    return;
                }
                if (Request.HttpMethod.Equals("POST")) {
                    var pos = Request.InputStream.Position;
                    Request.InputStream.Position = 0;
                    var ln = Request.InputStream.Length;
                    using (var sr = new StreamReader(Request.InputStream))
                    {
                        this.RequestBody = sr.ReadToEnd();
                        ln = Request.InputStream.Length;
                        Request.InputStream.Position = pos;
                        logger.Info("RequestBody:" + RequestBody);
                    }
                    if (!Signature())
                    {
                        filterContext.Result = Json(new
                        {
                            code = ResponseCode.错误请求,
                            message = "认证失败!",
                        });
                    }
                }
            }
  • 相关阅读:
    使用python写天气预告
    beef配合ettercap批量劫持内网的浏览器
    html布局
    python 使用paramiko模块上传本地文件到ssh
    mysql一些函数的记录
    python与ssh交互
    html笔记4
    html笔记3
    html笔记2
    html笔记1
  • 原文地址:https://www.cnblogs.com/cxxtreasure/p/14183077.html
Copyright © 2011-2022 走看看