go - 多路复用处理程序未接收到从 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 部分。任何的想法 ?
提前致谢。
解决方案
URLhttp://localhost:8080/resize?width=100&height=100
包含一个特殊字符,它对shell&
具有另一种含义。
为了在 URL 中使用和号 ( &
) 作为实际字符,您需要将 URL 放在引号中:“ http://localhost:8080/resize?width=100&height=100
”
推荐阅读
- python - 熊猫枢轴值被合并
- angular - 从指令中设置 ngIf 的 Angular 指令
- firebase - Is there a way to monitor which button the user clicks when using Firebase in-app messaging?
- python - trying to read every number in a text file python
- r - r - how do I print ggplot objects from a nested tibble in a reactable with expandable rows?
- python - 使用条件python发送密钥
- javascript - 异步/等待:UnhandledPromiseRejectionWarning:RangeError:超出最大调用堆栈大小
- angular - 如何在单击时删除按钮(Angular)?
- nginx - Nginx 应用程序在根站点上重定向
- r - 如何根据每组的滞后应用公式