代码:
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
router.POST("/post", func(c *gin.Context) {
ids := c.QueryMap("ids")
names := c.PostFormMap("names")
fmt.Printf("ids: %v; names: %v", ids, names)
})
router.Run(":8080")
}
运行代码
服务端发送访问请求
curl -H "Content-Type: application/x-www-form-urlencoded" \
-X POST \
-d 'names[first]=thinkerou&names[second]=tianou' \
"http://localhost:8080/post"
服务端运行显示