G
G
glodev2020-11-11 17:57:18
API
glodev, 2020-11-11 17:57:18

Implementation of post request to vk api?

I made requests to VK via get without problems)

resp, err := http.Get("https://api.vk.com/method/users.get?user_ids=" + id + "&fields=about,activities,books .....

Rested on the limitation of the volume (length) of the request, in fact, it is customary to switch to POST
resp, err := http.Post("https://api.vk.com/method/users.get","POST",_)

Interested in how to correctly pass the request, and parameters such as user sheet and fields?
Which contentType string to choose and how to properly pass fields to body io.Reader

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
glodev, 2020-11-16
@glodev

Content type can be used application/x-www-form-urlencoded, in the body you can pass exactly those parameters that do not pass along the length in GET. For example, if you need to send a long text.
The body format can be found on Wikipedia https://ru.wikipedia.org/wiki/POST_(HTTP) .
Vkontakte support team

B
basrach, 2020-11-14
@basrach

import (
...
    "net/http"
    "net/url"
    "strings"
...
)

func main() {
...
        data := url.Values{}
  data.Add("user_ids", id)
  data.Add("fields", "about")
  data.Add("fields", "activities")
  data.Add("fields", "books")

  resp, err := http.Post("https://api.vk.com/method/users.get", "POST", strings.NewReader(data.Encode()))
...
}

N
NonameProgrammer, 2020-11-11
@NonameProgrammer

POST will not play a role here. Divide the required parameters into two parts and make two requests.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question