I can access GET
parameters using mux:
import (
"github.com/gorilla/mux"
)
func main(){
rtr := mux.NewRouter()
rtr.HandleFunc("/logon", logonGet).Methods("GET")
}
func logonGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
login := params["login"]
}
But cannot figure out how to access POST
params
func main(){
rtr := mux.NewRouter()
rtr.HandleFunc("/logon", logonPost).Methods("POST")
}
func logonPost(w http.ResponseWriter, r *http.Request) {
// how to get POST parameters from request
}
Method postHandle () After handling a request, our model parameters are available, so we may access them to change values or add new ones. In order to do that, we use the overridden postHandle () method: Let's take a look at the implementation details. First of all, it's better to check if the model is not null.
In an HTTP POST request, the parameters are not sent along with the URI. Where are the values? In the request header? In the request body? What does it look like? Show activity on this post. The values are sent in the request body, in the format that the content type specifies.
Every event handler has a status parameter that controls the event handler. For Complete events, this parameter is also used to indicate the success or failure of the operation that generated the event.
In a POST handler, the parameter name must match a form field name for the incoming value to be automatically bound to the parameter: Alternatively, you can use the form tag helper's asp-route attribute to pass parameter values as part of the URL, either as a query string value or as route data for GET requests:
By using (*http.Request).FormValue
method.
func logonPost(w http.ResponseWriter, r *http.Request) {
login := r.FormValue("login")
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With