HTTP POST in GO Lang throws error -
i trying make post request using in go lang. api url expecting username , password field passed in body. keep getting below error ?
i not sure doing wrong here ?
error
url.values undefined (type string has no field or method values)
go function
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 reach server.") } else { body, _ := ioutil.readall(resp.body) fmt.println("body=", string(body)) } }
the argument makehttppostreq
states url string treating struct url.values
, error
has no field or method
Comments
Post a Comment