• 当 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 = "认证失败!",
                        });
                    }
                }
            }
  • 相关阅读:
    做人做事
    不骄不躁
    争取
    收入
    Windows 7下的Comodo Firewall免费防火墙
    成功水平
    成家立业
    Windows无法安装到GPT格式磁盘的根本解决办法
    安装Windows10操作系统
    安装操作系统的几种方式
  • 原文地址:https://www.cnblogs.com/cxxtreasure/p/14183077.html
Copyright © 2020-2023  润新知