获取Get和Post参数

func main() {

	// /post?id=1234&page=1 HTTP/1.1
	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.JSON(200, gin.H{
			"id": id,
			"page": page,
			"name": name,
			"message": message,
		})
	})

	router.Run(":8080")
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<form action="http://127.0.0.1:8080/post?id=1234&page=1 HTTP/1.1" method="post" action="application/x-www-form-urlencoded">
    用户名:<input type="text" name="name" placeholder="请输入你的用户名">  <br>
    密   码:<input type="password" name="message" placeholder="请输入你的密码">  <br>
    <input type="submit" value="提交">
</form>
</body>
</html>

 

原文地址:https://www.cnblogs.com/yzg-14/p/13141898.html