M
M
Muxauko2020-04-15 16:12:36
go
Muxauko, 2020-04-15 16:12:36

How to send a post request message from a VKontakte group?

In Python, earlier, when sending a message on behalf of the VKontakte group, I made a Get request and listed methods, and simply gave a string to the message method. In Go this doesn't work, because here the get request doesn't understand spaces, you have to put "+" instead of each space to send more than one word in the message, but it's a chore. Never dealt with post requests before. Please tell me how to make a post request to send a specific message from a group to a specified user_id, please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Romanov, 2020-04-15
@Muxauko

package main

import (
    "fmt"
    "log"
    "net/http"
    "os"
)

func main() {
    req, err := http.NewRequest("GET", "http://****", nil)
    if err != nil {
        log.Print(err)
        os.Exit(1)
    }

    q := req.URL.Query()
    q.Add("api_key", "key_from_environment_or_flag")
    q.Add("another_thing", "foo & bar")
    req.URL.RawQuery = q.Encode()

    fmt.Println(req.URL.String())
    // http://***?another_thing=foo+%26+bar&api_key=key_from_environment_or_flag
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question