You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FormValue returns the first value for the named component of the query. POST and PUT body parameters take precedence over URL query string values. FormValue calls ParseMultipartForm and ParseForm if necessary and ignores any errors returned by these functions. If key is not present, FormValue returns the empty string. To access multiple values of the same key, call ParseForm and then inspect Request.Form directly.
application/x-www-form-urlencoded form body (POST, PUT, PATCH only)
query parameters (always)
multipart/form-data form body (always)
So far as I can tell, this has been the case since Request.PostForm was added in https://golang.org/cl/6210067. Prior to that CL, query parameters always took precedence over form bodies.
CL 6210067 added this line to the ParseForm documentation:
// POST and PUT body parameters take precedence over URL query string values.
This is only true for application/x-www-form-urlencoded body parameters. I don't know if this was intentional or not; it seems plausible that it was unintentional. Whether intentional or not, either the documentation or the function behavior needs to be updated.
Go version
go version go1.20.6 darwin/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
https://pkg.go.dev/net/http#Request.FormValue
FormValue returns the first value for the named component of the query. POST and PUT body parameters take precedence over URL query string values. FormValue calls ParseMultipartForm and ParseForm if necessary and ignores any errors returned by these functions. If key is not present, FormValue returns the empty string. To access multiple values of the same key, call ParseForm and then inspect Request.Form directly.
Sample application:
https://go.dev/play/p/B_9IyJ7YTEL
What did you expect to see?
curl --location 'http://127.0.0.1:8080/?name=potato' --form 'name="orange"'
Expected output should be:
Because the POST and PUT body parameters take precedence over URL query string values.
What did you see instead?
Server output:
The text was updated successfully, but these errors were encountered: