Android客户端发送Post/Get请求到Asp.Net服务端一般处理程序Asp.Net进行参数解析

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DTK.MIS.Entities;
using System.Data;
using DTK.MIS.DAL;
using Newtonsoft.Json;
using DTK.MIS.Common;
using System.IO;

namespace DTKMIS.api
{
    /// <summary>
    /// GetCompanyInfoSearch 企业信息查询
    /// </summary>
    public class GetCompanyInfoSearch : IHttpHandler
    {

        PageBaseParent p = new PageBaseParent();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            CpyCompanyInfoEntity model = new CpyCompanyInfoEntity();
            CompanyInfoEntity entity = null;
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            using (var reader = new StreamReader(context.Request.InputStream))
            {
                String postJson = reader.ReadToEnd();
                entity = (CompanyInfoEntity)JsonConvert.DeserializeObject(postJson, typeof(CompanyInfoEntity));
            }
            int pagesize = 10;
            int pageindex = 1;
            int recordCount = -1;
            string SSFWD = "";
            string SSSQ = "";
            if (context.Request.RequestType.ToLower() == "post")
            {
                pagesize = entity.pagesize;
                pageindex = entity.pageindex;
                recordCount = entity.recordCount;
                model.QYMC = entity.QYMC;
                model.SSHY = entity.SSHY;
                SSFWD = entity.SSFWD;
                SSSQ = entity.SSSQ;
                model.ZZJGDM = entity.ZZJGDM;
                model.LXRXM = entity.LXRXM;
                model.Status = entity.Status;
            }
            DataTable dt = new DataTable();
            DataSet dsInfo = CpyCompanyInfoDalProvider.GetInstance().GetPagedWsysAPP(pagesize, pageindex, ref recordCount, model, SSFWD, SSSQ);
            dt = dsInfo.Tables[0];
            foreach (DataRow dr in dt.Rows)
            {
                dr["SSHY"] = p.GetBaseDateName(dr["SSHY"].ToString());
                dr["SSFWD"] = p.GetBSNameByID(dr["SSFWD"].ToString());
                dr["SSSQ"] = p.GetBSNameByID(dr["SSSQ"].ToString());
            }
            SetParameter para = new SetParameter();
            para.data.CompanyInfo = dt;
            para.recordCount = recordCount;
            para.state = 1;
            para.msg = "操作成功";
            string strJson = JsonConvert.SerializeObject(para);
            context.Response.Write(strJson);
        }
        public class SetParameter
        {
            public int recordCount;
            public int state;
            public string msg;
            public DataStatus data = new DataStatus();
        }
        public class DataStatus
        {
            public DataTable CompanyInfo { get; set; }
        }
        /// <summary>
        /// POST:参数实体类
        /// </summary>
        public class CompanyInfoEntity
        {
            public int pagesize { get; set; }
            public int pageindex { get; set; }
            public int recordCount { get; set; }
            public string QYMC { get; set; }
            public int SSHY { get; set; }
            public string SSFWD { get; set; }
            public string SSSQ { get; set; }
            public string ZZJGDM { get; set; }
            public string LXRXM { get; set; }
            public string Status { get; set; }
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

  

原文地址:https://www.cnblogs.com/xiaoyao095/p/4350710.html