D
D
ddddd tttt2019-01-11 11:48:41
go
ddddd tttt, 2019-01-11 11:48:41

How to pass a nested array in query parameters?

LoginForm: [username: ..... , password:.....] , how to pass such an array to a post request. I then need to take it to php as $_POST["LoginForm"]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2019-01-11
@pashaa

client := http.DefaultClient

  form := url.Values{
    "LoginForm[username]": []string{"user"},
    "LoginForm[password]": []string{"pass"},
  }

  response, err := client.Post("http://httpbin.org/post", "application/x-www-form-urlencoded", strings.NewReader(form.Encode()))
  if err != nil {
    panic(err)
  }
  defer response.Body.Close()

  b, err := ioutil.ReadAll(response.Body)
  if err != nil {
    panic(err)
  }

  println(string(b))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question