Nancy的使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kingStormQueen/article/details/84546380

导入Nancy

Nancy的使用:

代码段:

using Nancy;
using Nancy.Extensions;
using Newtonsoft.Json;
using Serge.MES.Application.Service.BusiInfo.WMS.RecTallyOrder;
using System.Collections.Generic;

namespace Serge.Application.WebApi.LoginAuthority.Modules.BusiInfo
{
    public class TallyOrderApi : NancyModule
    {
        #region 模块对象
        private RecTallyOrderIBLL recTallyOrderBLL = new RecTallyOrderBLL();
        #endregion
        public TallyOrderApi():base("api/BusiInfo/TallyOrder")
        {
            Post["/GetTallyOrderInfo"] = para =>
            {
                //string postData = Request.Form[""];
                
                string postData = Request.Body.AsString();
                dynamic info = JsonConvert.DeserializeObject(postData);
                RecTallyOrderHEntity StationList = recTallyOrderBLL.GetEntity(info.HID.ToString(), info.WAREHOUSECODE.ToString());
                
                // 返回登录结果对象集
                return Response.AsJson(StationList);
            };
            Post["/GetList"] = para =>
            {
                
                    //string postData = Request.Form[""];
                    
                    string postData = Request.Body.AsString();
                    dynamic info = JsonConvert.DeserializeObject(postData);
                    IEnumerable<RecTallyOrderHEntity> StationList = recTallyOrderBLL.GetList(info.TALLYORDERNO.ToString(), info.BILLTYPE.ToString());
                    // 返回登录结果对象集
                    return Response.AsJson(StationList);

                
               
            };
            
        }
    }
}

使用postman来测试发送请求:

使用postman时,nancy接收请求用

string postData = Request.Form[""];

而不用:string postData = Request.Body.AsString();

当返回数据量多时,返回用return Response.AsText(json);

扫描二维码关注公众号,回复: 4283999 查看本文章

猜你喜欢

转载自blog.csdn.net/kingStormQueen/article/details/84546380