WebApi NETCore框架 | APIProviderFactory 调用WebApi接口|C/S开发框架
作者:csframework|C/S框架网  发布日期:2023/02/07 18:14:49

WebApi NETCore框架 | APIProviderFactory 调用WebApi接口|C/S开发框架

APIProviderSign 类方法说明

WebApi NETCore框架 | APIProviderFactory 调用WebApi接口|C/S开发框架

Demo代码

C# 全选
 var input = new req_Demo { Key = "test111" };

            //RequestDataTableByGet	使用HTTPGET方式获取对象列表并转换为DataTable对象。
            var data1 = APIProviderFactory.Sign().RequestDataTableByGet<WebApi.Models.ModelUser>(APIList.Home_GetList, "");
            ShowResult(data1);

            //RequestDataTableByPost	使用HTTPPOST方式获取对象列表并转换为DataTable对象。
            var data2 = APIProviderFactory.Sign().RequestDataTableByPost<WebApi.Models.ModelUser>(APIList.Home_GetListWithSign, input);
            ShowResult(data2);

            //RequestListByGet	使用HTTPGET方式获取对象列表,返回List<T>类型对象。
            var data3 = APIProviderFactory.Sign().RequestListByGet<WebApi.Models.ModelUser>(APIList.Home_GetListWithParam, "key=1111");
            ShowResult(data3);

            //RequestListByPost	使用HTTPPOST方式获取对象列表,返回List<T>类型对象。
            var data4 = APIProviderFactory.Sign().RequestListByPost<WebApi.Models.ModelUser>(APIList.Home_GetListWithSign, input);
            ShowResult(data4);

            //RequestObjectByGet	使用HTTPGET方式获取单个对象,返回<T>类型对象。
            var data5 = APIProviderFactory.Sign().RequestObjectByGet<WebApi.Models.ModelUser>(APIList.Home_GetObjectWithSignByGet, "key=1111");
            ShowResult(data5);

            //RequestObjectByPost	使用HTTPPOST方式获取单个对象,返回<T>类型对象。
            var data6 = APIProviderFactory.Sign().RequestObjectByPost<WebApi.Models.ModelUser>(APIList.Home_GetObjectWithSignByPost, input);
            ShowResult(data6);

            //RequestObjectByGetAnyone	使用HTTPGET方式调用匿名接口,并返回<T>类型对象。
            var data7 = APIProviderFactory.Sign().RequestObjectByGetAnyone<WebApi.Models.ModelUser>(APIList.Home_GetObjectByGetWithAnonymous, "key=1111");
            ShowResult(data7);

            //RequestObjectByPostAnyone	使用HTTPPOST方式调用匿名接口,并返回<T>类型对象。
            var data8 = APIProviderFactory.Sign().RequestObjectByPostAnyone<WebApi.Models.ModelUser>(APIList.Home_GetObjectByPostWithAnonymous, input);
            ShowResult(data8);

APIList类

C# 全选
 #region 测试接口

        public const string Home_GetList = "/api/home/GetList";

        public const string Home_GetListWithParam = "/api/home/GetListWithParam";

        public const string Home_GetListWithSign = "/api/home/GetListWithSign";

        public const string Home_GetObjectWithSignByPost = "/api/home/GetObjectWithSignByPost";

        public const string Home_GetObjectWithSignByGet = "/api/home/GetObjectWithSignByGet";
        
        public const string Home_GetObjectByPostWithAnonymous = "/api/home/GetObjectByPostWithAnonymous";

        public const string Home_GetObjectByGetWithAnonymous = "/api/home/GetObjectByGetWithAnonymous";

        

        #endregion

Demo控制器

C# 全选
[ApiController]
    [Route("api/[controller]/[action]")]
    [OpenApiTag("CSFramework.WebApi.NETCore框架  - Demo 控制器")]
    public class HomeController : _BaseController
    {

        [AllowAnonymous]
        [HttpGet]
        public List<ModelUser> GetList()
        {
            return new List<ModelUser>() { new ModelUser { Account = "111" }, new ModelUser { Account = "222" } };
        }

        [AllowAnonymous]
        [HttpPost]
        public List<ModelUser> GetListByPostWithAnonymous(req_Demo input)
        {
            return new List<ModelUser>() { new ModelUser { Account = "8888" }, new ModelUser { Account = "9999" } };
        }

        [AllowAnonymous]
        [HttpPost]
        public ModelUser GetObjectByPostWithAnonymous(req_Demo input)
        {
            return new ModelUser { Account = "8888>>" + input.Key };
        }

        [AllowAnonymous]
        [HttpGet]
        public ModelUser GetObjectByGetWithAnonymous(string key)
        {
            return new ModelUser { Account = "8888>>" + key };
        }

        [HttpPost]
        public List<ModelUser> GetListWithSign(req_Demo input)
        {
            return new List<ModelUser>() { new ModelUser { Account = "8888" }, new ModelUser { Account = "9999" } };
        }

        [AllowAnonymous]
        [HttpGet]
        public List<ModelUser> GetListWithParam(string key)
        {
            return new List<ModelUser>() { new ModelUser { Account = "111>>" + key }, new ModelUser { Account = "222>>" + key } };
        }

        [HttpPost]
        public ModelUser GetObjectWithSignByPost(req_Demo input)
        {
            return new ModelUser { Account = "8888>>" + input.Key };
        }

        [HttpGet]
        public ModelUser GetObjectWithSignByGet(string key)
        {
            return new ModelUser { Account = "8888>>" + key };
        }


    }

C/S框架网|原创精神.创造价值.打造精品


扫一扫加作者微信
C/S框架网作者微信 C/S框架网|原创作品.质量保障.竭诚为您服务
上一篇 下一篇