You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Need to add docs how to use ctx method AbortWithStatusJSON
var ucr messages.UsersCreateRequest
if e := c.BindJSON(&ucr); e != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
"errors": "someError",
})
}
fmt.Println(1)
response should be application/json; charset=utf-8 BUT it gives content-type == 'text/plain; charset=utf-8'
1 I thought I will not need to write return If I will use AbortWithStatusJSON.
I'm getting in response headers content-type == 'text/plain; charset=utf-8' even if I using c.JSON:
var ucr messages.UsersCreateRequest
if e := c.BindJSON(&ucr); e != nil {
c.JSON(http.StatusBadRequest, gin.H{
"errors": "bsalslasalksaslas"
})
return
}
The text was updated successfully, but these errors were encountered:
mymtw
changed the title
AbortWithStatusJSON not returning response. Need to add docs for ctx method AbortWithStatusJSON
AbortWithStatusJSON and JSON returns wrong response headers
Aug 3, 2017
@appleboy thank you, works.
I'm closing this issue and:
I didn't find in README.md (docs) anything about using this ShouldBindWith.
it will be better to update the doc, even the note like if you wanna get content-type == 'application/json' in response, then you need to use c.ShouldBindWith(&something, binding.JSON); instead of c.BindJSON.
Cuz, on my frontend I'm checking content-type in response, in my tests on backend not. Frontend didn't work correctly for me.
Thx
gin latest version. 1.2
AbortWithStatusJSON
response should be
application/json; charset=utf-8
BUT it givescontent-type == 'text/plain; charset=utf-8'
return
If I will use AbortWithStatusJSON.content-type == 'text/plain; charset=utf-8'
even if I using c.JSON:The text was updated successfully, but these errors were encountered: