同时接收 post 参数和 query 参数。
query_post.go:
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"net/http"
)
func main() {
router := gin.Default()
router.POST("/post", func(c *gin.Context) {
id := c.Query("id")
page := c.DefaultQuery("page", "0")
name := c.PostForm("name")
message := c.PostForm("message")
c.String(http.StatusOK, fmt.Sprintf("id: %s; page %s; name: %s; message: %s", id, page, name, message))
})
router.Run(":8080")
}
测试:
$ curl -d "name=manu&message=this_is_great" "http://localhost:8080/post?id=1234&page=1"
输出:
id: 1234; page 1; name: manu; message: this_is_great