As explained in this question, you probably don't actually want to do this. Most servers won't do anything useful with a form body in a GET
request—and most that do will just treat it as synonymous with the same parameters sent in a query string, in which case you should just put them in the query string of your url.URL
object in the first place.
However, if you do have a good reason to do this, you can. As the docs you linked explain, PostForm
is just a thin convenience wrapper around NewRequest
and Do
. Just as you're expected to use NewRequest
yourself if you want to add custom headers, you can use it to attach a body.
And if you look at the source to PostForm
, it's pretty trivial:
return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
Basically, instead of this:
resp, err := client.PostForm(url, data)
… you do this:
body := strings.NewReader(data.Encode())
req, err := http.NewRequest("GET", url, body)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := client.Do(req)