我正在尝试在 GO Lang 中使用 Post 请求。API URL 期望在正文中将用户名和密码字段传递给它。但是我不断收到以下错误?我不确定我在这里做错了什么?错误 url.Values undefined (type string has no field or method Values)去函数func makeHttpPostReq(url string, username string, password string){ client := http.Client{} req, err := http.NewRequest("POST", url, url.Values{"username": {username}, "password": {password}}) req.Header.Add("Content-Type", "application/x-www-form-urlencoded") resp, err := client.Do(req) if err != nil { fmt.Println("Unable to reach the server.") } else { body, _ := ioutil.ReadAll(resp.Body) fmt.Println("body=", string(body)) }}
- 2 回答
- 0 关注
- 580 浏览
添加回答
举报
0/150
提交
取消