2.GO的get,post,delect,put

GO的get,post,delect,put

get请求

r := gin.Default()//中间件
	r.GET("/path/:id", func(c *gin.Context) {
    
      //查   :id占位表达式
		id := c.Param("id")
		user := c.DefaultQuery("user","admin")//
		pwd := c.Query("pwd")
		c.JSON(200, gin.H{
    
    
			"get请求的": id,
			"user": user,
			"pwd": pwd,
		})
	})

go的get请求

post请求

r.POST("/path", func(c *gin.Context) {
    
      //   :id占位表达式
		user := c.DefaultPostForm("user","admin")
		pwd := c.PostForm("pwd")
		c.JSON(200, gin.H{
    
    
			"user": user,
			"pwd": pwd,
		})
	})

go的post请求

put请求和post请求一样


和delect区别是一个可以从body拿参数,一个不能只能在请求头里拿参数

delect请求和get请求一样

猜你喜欢

转载自blog.csdn.net/qq_37214461/article/details/121884181
今日推荐