1
votes

On Chrome's Network tab the request payload looks like the following:

{"req":{"headers":{"headers":{"Authorization":"Bearer **************"}}},"name":"john"}

I removed the bearer authorization.

func name(c *gin.Context) {    
    name := c.Param("name")
    fmt.Println("name", name)
}

I'm most definitly doing something wrong but I've searched and couldn't find the solution. How do I retrieve something from there? If I use the rawData function I can see that the server got the response but I don't know how to actually put it in a variable that I can use

1
I assume GetHeader reads an HTTP header and not the body, and the payload looks like the http request's json body. HTTP headers and HTTP body are not one and the same part of an HTTP request. (en.wikipedia.org/wiki/…)mkopriva
I'm not sure you understood what I mean @mkopriva. I updated the code with only what is not workinguser4307777
Right you are, I misunderstood. However, you're still using the wrong method to read the HTTP body. Param is for reading path parameters.mkopriva
So which one is it? I've tried basically all of them to see if any worked but none diduser4307777
Given the payload's syntax I assume you're sending json in the request's body, to read that use binding github.com/gin-gonic/gin#model-binding-and-validationmkopriva

1 Answers

0
votes
data, _ := ioutil.ReadAll(c.Request.Body)
fmt.Printf("ctx.Request.body: %v", string(data))