Below is the code i've being working on.It shows success message when is run but doesn't shows the value defined in the post man form .Instead it shows blank spaces in command prompt.
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
func saveCustomer(c *gin.Context){
fn := c.PostForm("firstName")
ln := c.PostForm("lastName")
em := c.PostForm("email")
phnno := c.PostForm("phone_no")
fmt.Printf("fn: %v; ln: %v ; em: %v ; phnno: %v ;",fn ,ln ,em ,phnno )
c.String(200, "Success")
}
func main() {
r := gin.Default()
r.POST("/saveCustomer", saveCustomer)
r.Run(":8080")
}
here, no values are shown, instead blank spaces are shown
and below is the postman data fields with success message.
maybe you should using x-www-form-urlencoded instead?
func main() {
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")
}
data post:
POST /post?id=1234&page=1 HTTP/1.1
Content-Type: application/x-www-form-urlencoded
name=manu&message=this_is_great