C# .net 接口接收不同类型参数

 C# .net 接口接收不同类型参数_第1张图片

        public ActionResult ccbwx_notifyurl()
        {

                #region 请求参数
                Hashtable has = new Hashtable();
                System.Collections.Specialized.NameValueCollection collection;
                //if (this.HttpContext.Request.HttpMethod.ToUpper() == "POST")
                //{
                collection = this.HttpContext.Request.Form;
                foreach (string k in collection)
                {
                    string v = (string)collection[k];
                    if(!has.ContainsKey(k))
                    {
                        has.Add(k, v);
                    }
                   
                }
                //}

                collection = this.HttpContext.Request.QueryString;
                foreach (string k in collection)
                {
                    string v = (string)collection[k];
                    if (!has.ContainsKey(k))
                    {
                        has.Add(k, v);
                    }
                }
                try
                {
                    if (this.HttpContext.Request.InputStream.Length > 0)
                    {
                        #region body=raw、binary
                        try
                        {

                            Int32 strLen, strRead;
                            System.IO.Stream str = Request.InputStream;
                            strLen = Convert.ToInt32(str.Length);
                            byte[] strArr = new byte[strLen];
                            strRead = str.Read(strArr, 0, strLen);

                            String strmContents = System.Text.Encoding.UTF8.GetString(strArr);
                            //strmContents = System.Text.Encoding.ASCII.GetString(strArr);
                            //strmContents = System.Text.Encoding.Default.GetString(strArr);
                            Dictionary dir = JsonConvert.DeserializeObject>(strmContents);
                            foreach (KeyValuePair dv in dir)
                            {
                                if (!has.ContainsKey(dv.Key))
                                {
                                    has.Add(dv.Key, dv.Value);
                                }
                            }
                        }
                        catch { }
                        #endregion

                        #region  
                        try
                        {
                            XmlDocument xmlDoc = new XmlDocument();
                            xmlDoc.Load(this.HttpContext.Request.InputStream);
                            XmlNode root = xmlDoc.SelectSingleNode("xml");
                            XmlNodeList xnl = root.ChildNodes;

                            foreach (XmlNode xnf in xnl)
                            {
                                if (!has.ContainsKey(xnf.Name))
                                    has.Add(xnf.Name, xnf.InnerText);
                            }
                        }
                        catch { }
                        #endregion
                    }
                }
                catch (Exception ex)
                {

                }

                #endregion

               return Content("success");

}
 

你可能感兴趣的:(C#,开发语言,接口)