Files
Go-StudyExample/example/gin/8-QueryPostForm_test.go

35 lines
728 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* @Author : huangzj
* @Time : 2020/12/8 9:39
* @Description
*/
package gin
import (
"fmt"
"github.com/gin-gonic/gin"
"testing"
)
//read note POST /post?id=1234&page=1 HTTP/1.1
// Content-Type: application/x-www-form-urlencoded
// name=manu&message=this_is_great
//read note Query是用来解析地址栏中的参数
// PostForm是用来解析报文体中的参数
func TestQueryPostForm(t *testing.T) {
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")
fmt.Printf("id: %s; page: %s; name: %s; message: %s", id, page, name, message)
})
router.Run(":8080")
}