英文:
multiple-value http.PostForm() in single-value context in go
问题
在使用net/http
和net/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(对于Client
和Response
都是如此)返回(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"}})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论