-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get request body #1295
Comments
You should use |
|
Unless if I misunderstand the question, the code you provided worked for me when I tested it @lucky-lee ... I added a line to return the reqBody in the response:
I started up the server:
Made a curl request to test it which worked:
|
@jeffxf I found the problem because I called it once in the middleware, so I couldn't get it in the method. |
@jeffxf
}` you can run this demo, reqBody and reqBody2 have different value in fmt.Println |
@liuzhiwang Alternatively, you could add this line if you insist on making what you have work which will write the body back to the request after you read it: Example:
|
I'm here asking for the same issue:
I've tried to use |
@jeffxf thanks!!!!! |
i want get request body in function,but request body is empty.
code such as:
func LiveRecord(c *gin.Context) {
buf := make([]byte, 1024)
num, _ := c.Request.Body.Read(buf)
reqBody := string(buf[0:num])
}
but reqBody is empty,who can tell me how to use?
The text was updated successfully, but these errors were encountered: