首页 > 解决方案 > 多路复用处理程序未接收到从 curl post 传递的所有查询参数

问题描述

我无法使用 Mux 接收所有查询参数。只收到第一部分

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..
}

当我使用 curl 调用 apicurl -XPOST http://localhost:8080/resize?width=100&height=100 -o img_resize.png -F "file=@snap1.png"这是它打印的内容:

/resize?width=100
100

似乎它省略了 &height=100 部分。任何的想法 ?

提前致谢。

标签: gomux

解决方案


URLhttp://localhost:8080/resize?width=100&height=100包含一个特殊字符,它对shell&具有另一种含义。

为了在 URL 中使用和号 ( &) 作为实际字符,您需要将 URL 放在引号中:http://localhost:8080/resize?width=100&height=100


推荐阅读