Accessing Query String Parameters in Go's POST Requests
In Golang's http package, when handling POST requests, accessing the query string can be done by parsing the Request object's query parameters. The Request type provides the Query method, which returns a Values map containing the key-value pairs of the query string.
Example
Consider a POST request with a URL like:
http://host:port/something?param1=b
To access the GET parameters in Go:
func newHandler(w http.ResponseWriter, r *http.Request) { fmt.Println("GET params were:", r.URL.Query()) // Get a single parameter param1 := r.URL.Query().Get("param1") // Get multiple parameters or empty values param1s := r.URL.Query()["param1"] }
Note:
The above is the detailed content of How Do I Access Query String Parameters in Go's POST Requests?. For more information, please follow other related articles on the PHP Chinese website!