The following content is reproduced from https://blog.csdn.net/weixin_36344862/article/details/111932206
As mentioned above, there are several forms of post sending data, form and stream are the most commonly used. Especially use httpc in the program
package main
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
router.POST("/events", events)
router.Run(":5000")
}
func events(c *gin.Context) {
buf := make([]byte, 1024)
n, _ := c.Request.Body.Read(buf)
fmt.Println(string(buf[0:n]))
resp := map[string]string{"hello": "world"}
c.JSON(http.StatusOK, resp)
/*post_gwid := c.PostForm("name")
fmt.Println(post_gwid)*/
}
lients are generally considered to be sent through the stream. In php, it is obtained through php://input. In gin, you can pass c.Request.Body.Read(buf). The specific code is as follows: