curl http://127.0.0.1:8080/users -X POST -d 'name=juanmaofeifei&age=10'
package main
import (
"github.com/gin-gonic/gin"
"strconv"
)
func main() {
router := gin.Default()
router.POST("/users", func(c *gin.Context) {
name := c.PostForm("name")
ageStr := c.DefaultPostForm("age", "20")
age, _ := strconv.Atoi(ageStr)
c.JSON(200, gin.H{
"name" : name,
"age" : age,
})
})
router.Run(":8080")
}
//{"age":10,"name":"juanmaofeifei"}
curl http://10.6.27.137:8080/users -X POST -d 'id=1&id=2&id=3'
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
router.POST("/users", func(c *gin.Context) {
idSli := c.PostFormArray("id")
c.JSON(200, gin.H{
"ids" : idSli,
})
})
router.Run(":8080")
}
//{"ids":["1","2","3"]}
curl http://10.6.27.137:8080/users -X POST -d 'user[name]=juanmaofeifei&user[age]=20'
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
router.POST("/users", func(c *gin.Context) {
user := c.PostFormMap("user")
c.JSON(200, gin.H{
"user" : user,
})
})
router.Run(":8080")
}
//{"user":{"age":"20","name":"juanmaofeifei"}}