zoukankan      html  css  js  c++  java
  • 获取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>
    

     

  • 相关阅读:
    MFC
    AC自动机
    KMP
    Power Transmission (Hard Edition)
    Floyd
    地杰斯特算法
    二叉树
    51nod 1002 数塔取数问题【dp】
    51nod1049 最大子段和【动态规划】
    poj2385
  • 原文地址:https://www.cnblogs.com/yzg-14/p/13141898.html
Copyright © 2011-2022 走看看