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;
}
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;
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 "";