我是Go和Gin的新手,我在打印完整的请求正文时遇到了麻烦.
我希望能够从第三方POST读取请求正文,但我得到空请求正文
curl -u dumbuser:dumbuserpassword -H "Content-Type: application/json" -X POST --data '{"events": "3"}' http://localhost:8080/events
Run Code Online (Sandbox Code Playgroud)
我的整个代码如下.任何指针都很赞赏!
package main
import (
"net/http"
"fmt"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
authorized := router.Group("/", gin.BasicAuth(gin.Accounts{
"dumbuser": "dumbuserpassword",
}))
authorized.POST("/events", events)
router.Run(":8080")
}
func events(c *gin.Context) {
fmt.Printf("%s", c.Request.Body)
c.JSON(http.StatusOK, c)
}
Run Code Online (Sandbox Code Playgroud) go ×1