Using the url package https://golang.org/pkg/net/url/#pkg-overview, one can create some data to send in an api request like so (referencing this post):
hc := http.Client{} req, err := http.NewRequest("POST", APIURL, nil) form := url.Values{} form.Add("ln", "value") form.Add("ip", "value2") form.Add("ua", "value3") req.PostForm = form req.Header.Add("Content-Type", "application/x-www-form-urlencoded") glog.Info("form was %v", form) resp, err := hc.Do(req)
My question is, how can one send nested json values? Something like:
form.Add("ln", {"nestedKey": nestedvalue})
Is this possible? How can one send nested values? More generally, how can one send a json body in a request?
https://stackoverflow.com/questions/66956372/how-to-generate-deeply-nested-fields-for-api-request-using-url-values April 06, 2021 at 12:34AM
没有评论:
发表评论