在Go语言中,将`http.PostForm()`的多个返回值用于单个值的上下文中。

huangapple go评论142阅读模式
英文:

multiple-value http.PostForm() in single-value context in go

问题

在使用net/httpnet/url进行单个键值对时,我遇到了以下错误:

在单值上下文中使用多值 http.PostForm()
英文:

While using net/http and net/url for single key value I am getting this error

multiple-value http.PostForm() in single-value context

答案1

得分: 3

你的错误可能是由于单值赋值引起的- PostForm(对于ClientResponse都是如此)返回(resp *Response, err error)(值和错误),所以你需要像这样做:

resp, err := http.PostForm("http://example.com/form", url.Values{"key": {"Value"}, "id": {"123"}})

而你正在做的是(我的建议)

resp := http.PostForm("http://example.com/form", url.Values{"key": {"Value"}, "id": {"123"}})
英文:

Your error possibly caused by single-value assignment — PostForm (both for Client and Response) returns (resp *Response, err error) (value and an error), so you need to do something like:

resp, err := http.PostForm("http://example.com/form", url.Values{"key": {"Value"}, "id": {"123"}})

while you doing (my suggestion)

resp := http.PostForm("http://example.com/form", url.Values{"key": {"Value"}, "id": {"123"}})

huangapple
  • 本文由 发表于 2014年3月27日 16:02:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/22681479.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定