K
K
kireke2021-08-12 21:26:57
go
kireke, 2021-08-12 21:26:57

How do I get the body that was submitted by gin gonic golang?

package main

import (
  "fmt"
  "github.com/gin-gonic/gin"
)
func main()  {
  fmt.Println("Hello, world!")
  r := gin.Default()
  r.POST("/", func(c *gin.Context) {
    body := c.Request.Body
    c.JSON(200,body);
  })
  r.Run(":8080");
}

I make a request through postman in body json
{
     "email": "[email protected]",
    "password": "test"
  }

and in response I get an empty json {}
, what should I do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Mamonov, 2021-08-12
@kireke

Try like this

jsonDataBytes, err := ioutil.ReadAll(c.Request.Body)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question