I am not able to receive all the query parameters using Mux. Only the first part is received
func main() {
router := mux.NewRouter()
router.HandleFunc("/resize", resizeImageFromPayload).Methods("POST")
log.Fatal(http.ListenAndServe(":8080", router))
}
func resizeImageFromPayload(w http.ResponseWriter, r *http.Request) {
widthParameter := r.URL.Query().Get("width")
heightParameter := r.URL.Query().Get("height")
fmt.Println(r.URL.String())
fmt.Println(widthParameter)
fmt.Println(heightParameter)
//More code..
}
When I call the api using curl curl -XPOST http://localhost:8080/resize?width=100&height=100 -o img_resize.png -F "file=@snap1.png"
This is what it prints:
/resize?width=100
100
it seems like it omitted the &height=100 part. Any idea ?
Thanks in advance.
The URL http://localhost:8080/resize?width=100&height=100
contains a special character &
that has another meaning to shell.
In order to use ampersand (&
) as an actual character inside the URL, you need to put the URL in quotes: "http://localhost:8080/resize?width=100&height=100
"