zoukankan      html  css  js  c++  java
  • asp.net中后台获取Post参数(Json)最简单的一种方法。

    哈喽小伙伴们大家好,

    在日常开发中,有很多时候,或者某些情况下在一些Post接口里面参数都是用json 作为收发协议

    而这时也不确定后续的格式是否会有调整等等出于其他考虑,所以不在Controller里直接写对应的参数Entity。

    那么怎么获取对方Post过来的值呢?

    答案其实很简单,复制粘贴以下这段代码。可以被多个方法公用。

    public class PostHelper
        {
            public static string GetQueryString()
            {
                using (Stream postData = HttpContext.Current.Request.InputStream)
                {
                    using (StreamReader sRead = new StreamReader(postData, Encoding.UTF8))
                    {
                        return sRead.ReadToEnd();
                    }
                }
            }
        }

    没错,这样就可以了,特别简单。

    快拿去用吧 

  • 相关阅读:
    【shell】 for循环
    【shell】case语句
    【shell】if语句
    【shell】nmap工具的使用
    spring3 循环依赖
    spring3 DI基础
    spring3系列一
    正则表达式学习网址
    常用正则表达式
    hibernate延迟加载
  • 原文地址:https://www.cnblogs.com/SevenWang/p/14824988.html
Copyright © 2011-2022 走看看