简体   繁体   中英

access post parameters in handler

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
}

By using (*http.Request).FormValue method.

func logonPost(w http.ResponseWriter, r *http.Request) {
    login := r.FormValue("login")
    // ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM