zoukankan      html  css  js  c++  java
  • .net 接收post 的参数 加载xml

      /// <summary>
        /// SimDataLimiHandler 的摘要说明  推送
        /// </summary>
        public class SimDataLimiHandler : IHttpHandler
        {
    
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/plain";
                //context.Response.Write("Hello World");
                try
                {
                    if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST")
                    {
                        using (Stream stream = HttpContext.Current.Request.InputStream)
                        {
                            //Byte[] postBytes = new Byte[stream.Length];
                            //stream.Read(postBytes, 0, (Int32)stream.Length);
                            //string postString = Encoding.UTF8.GetString(postBytes);
    
    
                            try
                            {
                                StreamReader reader = new StreamReader(stream);
                                string jsonStr = reader.ReadToEnd();
                                jsonStr = System.Web.HttpUtility.UrlDecode(jsonStr);//url解码
                                SortedList prams = Param(jsonStr);
                                for (int i = 0; i < prams.Count; i++)
                                {
                                    Log4netHelper.Debug("解析", "参数 " + prams.GetKey(i) + "" + prams.GetByIndex(i));
                                }
                                //声明一个XMLDoc文档对象,LOAD()xml字符串  
                                XmlDocument doc = new XmlDocument();
                                doc.LoadXml(prams.GetByIndex(0).ToString());
                                //得到XML文档根节点  
                                XmlElement root = doc.DocumentElement;
                                XmlNodeList list = root.ChildNodes;
                                foreach (XmlNode xno in list)
                                {
                                    Console.WriteLine(" 参数 " + xno.Name + "" + xno.InnerText);
    
                                }
                            }
                            catch (Exception ex)
                            {
                                Log4netHelper.Error("SimDataLimiHandler 数据解析出错", "接收推送", ex);
    
                            }
    
                        }
    
    
                    }
                }
                catch (Exception ex)
                {
                    string eventId = context.Request.Form["eventId"];
                    string data = context.Request.Form["data"];
                    Log4netHelper.Error("SimDataLimiHandler联通推送调用出错", "eventId:" + eventId + "data:" + data, ex);
                }
    
            }
    
    
    
            private SortedList Param(string POSTStr)
            {
    
                SortedList SortList = new SortedList();
                int index = POSTStr.IndexOf("&");
                string[] Arr = { };
                if (index != -1) //参数传递不只一项
                {
                    Arr = POSTStr.Split('&');
                    for (int i = 0; i < Arr.Length; i++)
                    {
                        int equalindex = Arr[i].IndexOf('=');
                        string paramN = Arr[i].Substring(0, equalindex);
                        string paramV = Arr[i].Substring(equalindex + 1);
                        if (!SortList.ContainsKey(paramN)) //避免用户传递相同参数
                        { SortList.Add(paramN, paramV); }
                        else //如果有相同的,一直删除取最后一个值为准
                        { SortList.Remove(paramN); SortList.Add(paramN, paramV); }
                    }
                }
                else //参数少于或等于1项
                {
                    int equalindex = POSTStr.IndexOf('=');
                    if (equalindex != -1)
                    { //参数是1项
                        string paramN = POSTStr.Substring(0, equalindex);
                        string paramV = POSTStr.Substring(equalindex + 1);
                        SortList.Add(paramN, paramV);
                    }
                    else //没有传递参数过来
                    { SortList = null; }
                }
                return SortList;
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
  • 相关阅读:
    Exp4 恶意代码分析 Week6
    Exp3 免杀原理与实践 Week5
    Exp2 后门原理与实践 Week4
    Exp1 PC平台逆向破解 Week3
    Exp0 Kali安装 Week1
    2018-2019-2 《网络对抗技术》Exp9 WebGoat 20165326
    2018-2019-2 《网络对抗技术》Exp8 Web基础 20165326
    2018-2019-2 《网络对抗技术》Exp7 网络欺诈防范 20165326
    2018-2019-2 《网络对抗技术》Exp6 信息搜集与漏洞扫描 20165326
    2018-2019-2 《网络对抗技术》Exp5 MSF基础应用 20165326
  • 原文地址:https://www.cnblogs.com/lucoo/p/6184222.html
Copyright © 2011-2022 走看看