In this code, if I comment the ParseForm() invocation the request works as expected
package main
import (
"fmt"
"net/http"
"net/url"
"strings"
)
func main() {
v := make(url.Values)
v.Set("status", "yeah!")
request, error := http.NewRequest("POST", "http://httpbin.org/post", strings.NewReader(v.Encode()))
if error != nil {
fmt.Println(error)
}
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
err:=request.ParseForm()
if err != nil {
fmt.Println(err)
}
fmt.Println(request.Form["status"])
response, error := http.DefaultClient.Do(request)
if error != nil {
fmt.Println(error)
} else {
fmt.Println(response)
}
}But if I call ParseForm() the body is cleared and I get:
Post http://httpbin.org/post: http: Request.ContentLength=14 with Body length 0Is like the Body length has been drained. How can I access the form values? I need to create a signature of the request. Is there other way to read the form values before the request is sent (other than creating the signature directly from the parameters directly? )