• .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;
                }
            }
        }
  • 相关阅读:
    composer 自动加载 通过classmap自动架子啊
    composer 自动加载一 通过file加载
    call_user_func函数
    array_filter与array_map
    array_filter、array_walk、array_map的区别
    array_filter函数
    基于visual Studio2013解决算法导论之012计数排序
    基于visual Studio2013解决算法导论之011快排改良
    基于visual Studio2013解决算法导论之010快排中应用插入排序
    基于visual Studio2013解决算法导论之009快速排序随机版本
  • 原文地址:https://www.cnblogs.com/lucoo/p/6184222.html
Copyright © 2020-2023  润新知