.net core api 接收参数

时间:2021-03-26 15:13:56   收藏:0   阅读:0

1.HttpGet请求

①.一点参数

        [HttpGet]
        public string TestGet(string name)
        {
            return name;
        }

②.一些参数(Test是自定义实体接收参数类)

        [HttpGet]
        public string TestGet([FromQuery] Test test) 
        {
            return test.name;
        }

2.HttpPost请求

①.前端传递序列化的参数 (contenttype:application/json,data:JSON.Stringfly(param))

        [HttpPost]
        public string TestPost([FromBody] Test test)
        {
            return test.name; 
        }

postman调用

技术图片

 

 

②.Form表单提交(带图片的)

        [HttpPost]
        public string TestPost([FromForm] Test test)
        {
            /*业务逻辑*/
            return test.name;
        } 

        public class Test
        {
            public string name { get; set; }
            public IFormFile file { get; set; }//图片

        }

postman调用:

技术图片

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!