1 #include "curl_interface.hpp"
2 curl_interface::curl_interface(std::string curl_collector_url):_curl_url(curl_collector_url){};
5 bool curl_interface::post_metrics(std::string & data){
7 CURL *curl = curl_easy_init();
12 struct curl_slist *headers = NULL;
13 headers = curl_slist_append(headers, "Content-Type:application/json");
15 /* point to ves collector */
16 curl_easy_setopt(curl, CURLOPT_URL, _curl_url.c_str());
19 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
21 /* size of the POST data */
22 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, data.length());
24 /* pass in a pointer to the data - libcurl will not copy */
25 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
27 result = curl_easy_perform(curl);
28 if (result != CURLE_OK){
29 _error.assign(curl_easy_strerror(result));
35 curl_easy_cleanup(curl);
39 _error.assign("Could not instantiate curl handle !");
46 std::string curl_interface::getError(void) const{