A
A
Andrey Antropov2020-06-09 12:47:31
C++ / C#
Andrey Antropov, 2020-06-09 12:47:31

VK LongPoll returns 404, what should I do?

I am using Curl for requests.

Getting a Server
params_map param;	

  auto ret = this->api->call("messages.getLongPollServer", "");        //он сам вставит версию и тд

  try
  {
    ret = ret["response"];
    this->_server = ret["server"].get<std::string>();
    this->_key = ret["key"].get<std::string>();
    this->ts = ret["ts"].get<eventnum>();
  }
  catch (std::exception & e)
  {
    std::cout << "GetLongPollServer error : " << e.what() << std::endl;
  }

The server itself is stored in a variable, but if you call it through the browser / code, then a 404 error

Request Method
std::string url = "https://" + this->_server;
  params_map data;
  data.insert({"acr", "a_check"});
  data.insert({ "key", this->_key });
  data.insert({ "ts", std::to_string(this->ts)});
  data.insert({ "wait", "25" });
  data.insert({ "mode", "10" });

    std::string res = this->api->request(url, Utils::data2str(data));
    if (res.empty()) {
        return nullptr;
    }

    try {
        json jres = json::parse(res);

        if (jres.find("error") == jres.end()) {
            return jres;
        }

        return jres;
    }
    catch (...) {

    }

    return nullptr;

this->api->request()
static char errorBuffer[CURL_ERROR_SIZE];
    curl_buffer.clear();

    CURL *curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
        curl_easy_setopt(curl, CURLOPT_USERAGENT, "VK API Client");
        curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, VK::Utils::CURL_WRITER);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &curl_buffer);

        CURLcode result = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
        if (result == CURLE_OK) {
            return curl_buffer;
        } else {
            return errorBuffer;
        }
    }
    curl_easy_cleanup(curl);

    return "";

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Yudakov, 2020-06-09
@AlexanderYudakov

Not familiar with the technologies you're using, but I'll venture a guess.
Judging by the call signature, this will be a POST:

std::string res = this->api->request(url, Utils::data2str(data));

And you need GET.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question