Ejemplo n.º 1
0
        /// <summary>
        /// 接受POST请求的参数
        /// </summary>
        /// <param name="controllerContext"></param>
        private void PostParams(HttpControllerContext controllerContext)
        {
            HttpContent content = controllerContext.Request.Content;

            if (content.IsFormData())
            {
            }
            Task <JObject> task = content.ReadAsAsync <JObject>();

            if (task != null)
            {
                JObject = task.Result;
                if (JObject != null)
                {
                    IpAddress = JObject.Value <string>("IpAddress");
                    PageSize  = JObject.Value <int>("pagesize");
                    PageIndex = JObject.Value <int>("pageindex");
                    var condtions = JObject.Value <JArray>("condtions");
                    if (condtions != null)
                    {
                        Condtions = condtions.ToObject <IList <Condtion> >();
                    }
                    var ordercondtions = JObject.Value <JArray>("ordercondtions");
                    if (ordercondtions != null)
                    {
                        OrderCondtions = ordercondtions.ToObject <IList <OrderCondtion> >();
                    }
                }
                else
                {
                    JObject = new JObject();
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PostData"/> class from <paramref name="content"/>.
 /// </summary>
 /// <param name="content">The <see cref="HttpContent"/> to initialize from.</param>
 public PostData(HttpContent content)
 {
     if (content != null)
     {
         MimeType = content.Headers?.ContentType?.ToString();
         if (content.IsFormData())
         {
             var bodyParams = HttpUtility.ParseQueryString(content.ReadAsStringAsync().Result);
             foreach (string key in bodyParams)
             {
                 Params.Add(new PostedParam {
                     Name = key, Value = bodyParams[key]
                 });
             }
         }
         else
         {
             Text = Encoding.UTF8.GetString(content.ReadAsByteArrayAsync().Result);
         }
     }
 }