I wanna get http body data use go.
My demo:
I set Content-Type: application/x-www-form-urlencoded
in http request header, there is no error, but I can't get http body data. Http Request Data like this:
I just wanna get the http body, I don't wanna use the method request.FormValue
. What should I do?
Invoke ParseForm
before reading the form values
r.ParseForm()
for k, v := range r.Form {
fmt.Println(k, v)
}
You need to run the request and get a response
client := &http.Client{}
resp, err := client.Do(r)
if err != nil {
fmt.Printf("Client Error: %v", err)
panic(err)
}
Then get the body
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf("Error reading body: %v", err)
panic(err)
}