Postman 调试请求Asp.NetCore3.1WebApi Get/Post/Put/Delete文件上传等

这里就直接截图了,如下(很简单的操作):

1:Get几种请求

 

2:Post

 

3:Put

 4:Delete

 最后,虽然简单,代码还是给放一下(这里只是抛砖引玉的作用,自己可以根据自身的业务需要来做进一步的优化和封装):

复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication.Models;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace WebApplication.Controllers
{
    [Route("api/[controller]")]
    public class ValuesController : Controller
    {
        // GET: api/<controller>
        [HttpGet]
        //public IEnumerable<string> Get()
        //{
        //    return new string[] { "value1", "value2" };
        //}

        //// GET api/<controller>/5


        //[HttpGet("{id}/{name}")]
        //public string Getother(int id, string name)
        //{
        //    return "id=" + id + ", name=" + name;
        //}

        //[HttpGet("{id}")]
        //public string GetByid(int id)
        //{
        //    return "value" + id;
        //}

        public string Get(Mystu student)
        {
            return student.name;
        }

        // POST api/<controller>
        [HttpPost]
        public void Post(string type, [FromBody]Mystu student)
        {
            string temp = type + $"id={student.id},name={student.name}";
        }

        // PUT api/<controller>/5
        [HttpPut()]
        public void Put(int id, [FromBody]Mystu student)
        {
            string pstr = $"id={id},sid={student.id},name={student.name}";
        }

        // DELETE api/<controller>/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
            string temp = $"长官{id}说:我们要把坏分子给清除掉";
        }
    }
    public class Mystu
    {
        public int id { get; set; }
        public string name { get; set; }
    }
}
View Code
复制代码

 5:新增文件上传

 6:PostMan请求参数为枚举类型

  枚举之外 取不到就为假,假就为0了,或者是默认值

 枚举的类:

 

 

 

 

 

 

posted @   天天向上518  阅读(1032)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示