• Query 和 post form

    Query 和 post form

    1. POST /post?id=1234&page=1 HTTP/1.1
    2. Content-Type: application/x-www-form-urlencoded
    3. name=manu&message=this_is_great
    1. func main() {
    2. router := gin.Default()
    3. router.POST("/post", func(c *gin.Context) {
    4. id := c.Query("id")
    5. page := c.DefaultQuery("page", "0")
    6. name := c.PostForm("name")
    7. message := c.PostForm("message")
    8. fmt.Printf("id: %s; page: %s; name: %s; message: %s", id, page, name, message)
    9. })
    10. router.Run(":8080")
    11. }
    1. id: 1234; page: 1; name: manu; message: this_is_great