代码:
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"
服务端运行显示

本文介绍如何使用Gin Web框架处理POST请求,通过示例代码展示了如何接收并解析客户端发送的表单数据,包括多值参数。通过curl命令演示了如何向服务器发送POST请求。

被折叠的 条评论
为什么被折叠?



