Jestem nowicjuszem Go and Gin i mam problem z wydrukowaniem pełnej treści żądania.gin/golang - Empty Req Body
Chcę być w stanie odczytać treści żądania POST z trzeciej strony, ale jestem coraz pusty prośba ciało
curl -u dumbuser:dumbuserpassword -H "Content-Type: application/json" -X POST --data '{"events": "3"}' http://localhost:8080/events
Cały mój kod jest jak poniżej. Każdy wskaźnik jest doceniany!
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)
}
Dziękuję, Danver, które naprawdę pomogły i były edukacyjne. –
Co należy zrobić, jeśli wiązanie się nie powiedzie? Ponieważ Czytelnik jest pusty, czy dane są po prostu tracone? – sean
Ja też chciałbym poznać odpowiedź na pytanie Seana. –