- With issues:
- Use the search tool before opening a new issue.
- Please provide source code and commit sha if you found a bug.
- Review existing issues and provide feedback or react to them.
Description
How to reproduce
package main
import (
"github.com/gin-gonic/gin"
)
type PostParam struct {
Name string `form:"name"`
Age string `form:"age"`
}
func main() {
r := gin.Default()
r.POST("/test-post", func(c *gin.Context) {
form := new(PostParam)
if err := c.ShouldBind(form); err != nil {
c.JSON(403, err.Error())
return
}
c.JSON(200, form)
})
r.Run(":3003")
}
Expectations
$ curl -i -H "Content-Type:application/json" -X POST http://127.0.0.1:3003/test-post
HTTP/1.1 403 Forbidden
Content-Type: application/json; charset=utf-8
Date: Fri, 29 Nov 2024 11:12:34 GMT
Content-Length: 5
"EOF"
Actual result
$ curl -i -H "Content-Type:application/json" -X POST http://127.0.0.1:3003/test-post
<{
"Name": "",
"Age": ""
}>
Environment
- go version:1.22.8
- gin version (or commit ref):1.10.0
- operating system:Windows 11
Comment From: VarusHsu
https://github.com/golang/go/blob/master/src/net/http/http.go#L174 Just catch this error then handle it. @niuge666
Comment From: niuge666
ok,thanks