diff --git a/src/api/API.cpp b/src/api/API.cpp index 720ee6e..ffa1a77 100644 --- a/src/api/API.cpp +++ b/src/api/API.cpp @@ -33,7 +33,6 @@ API::request(std::string myurl, bool post, Hashmap &ma std::string readString; if (curl) { - curl_easy_setopt(curl, CURLOPT_URL, myurl.c_str()); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); @@ -55,17 +54,21 @@ API::request(std::string myurl, bool post, Hashmap &ma curl_easy_setopt(curl, CURLOPT_POST, 1); curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, poststring.str().c_str()); } else { - std::string getstring; - for (int i = 0; i < map.size(); i++) { - getstring += map.getKey(i) + "=" + map.getValue(i); - if (i < map.size() - 1) { - getstring += "&"; + if (map.size() > 0) { + std::string getstring; + for (int i = 0; i < map.size(); i++) { + getstring += map.getKey(i) + "=" + map.getValue(i); + if (i < map.size() - 1) { + getstring += "&"; + } } - } - myurl += "?" + getstring; + myurl += "?" + getstring; + } } + curl_easy_setopt(curl, CURLOPT_URL, myurl.c_str()); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readString); diff --git a/src/api/TelegramAPI.cpp b/src/api/TelegramAPI.cpp index 985d144..6d2f9f5 100644 --- a/src/api/TelegramAPI.cpp +++ b/src/api/TelegramAPI.cpp @@ -5,6 +5,12 @@ #include "TelegramAPI.h" void TelegramAPI::sendMessage(std::string text) { - std::string reply = request("https://api.telegram.org/bot" + apikey + "/sendmessage?chat_id=" + chatid + "&text=" + text); + Hashmap args; + args.add("chat_id", chatid); + args.add("text", text); + + std::vector headers; + + std::string reply = request("https://api.telegram.org/bot" + apikey + "/sendmessage", false, args, headers); std::cout << "[DEBUG] " << reply << std::endl; }