30 CurlGet::writer(
char *
data,
size_t size,
size_t nmemb, std::string *buffer)
39 buffer->append(data, size * nmemb);
42 result = size * nmemb;
49 CurlGet::getErrorBuffer()
51 return &errorBuffer[0];
68 curl = curl_easy_init();
73 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, getErrorBuffer() );
74 curl_easy_setopt(curl, CURLOPT_URL, url.c_str() );
75 curl_easy_setopt(curl, CURLOPT_HEADER, 0);
76 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
77 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, this->writer);
78 curl_easy_setopt(curl, CURLOPT_WRITEDATA, getbuffer() );
81 result = curl_easy_perform(curl);
84 curl_easy_cleanup(curl);
87 if (result == CURLE_OK)
94 ss <<
"Error: [" << result <<
"] - " << errorBuffer;
95 throw std::string( ss.str() );
107 CurlPost::writer(
char *data,
size_t size,
size_t nmemb, std::string *buffer)
116 buffer->append(data, size * nmemb);
119 result = size * nmemb;
126 CurlPost::getErrorBuffer()
128 return &errorBuffer[0];
132 CurlPost::getreadbuffer()
138 CurlPost::getwritebuffer()
144 CurlPost::post(
const std::string &url,
const std::string &data,
const std::string &fields )
151 curl = curl_easy_init();
159 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, getErrorBuffer() );
160 curl_easy_setopt(curl, CURLOPT_URL, url.c_str() );
161 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fields.c_str() );
162 curl_easy_setopt(curl, CURLOPT_HEADER, 0);
163 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
164 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, this->writer);
165 curl_easy_setopt(curl, CURLOPT_WRITEDATA, getwritebuffer() );
168 result = curl_easy_perform(curl);
171 curl_easy_cleanup(curl);
174 if (result == CURLE_OK)
180 std::stringstream ss;
181 ss <<
"Error: [" << result <<
"] - " << errorBuffer;
182 throw std::string( ss.str() );
common derived classes for thrown exceptions
Implements a OO interface to CURL wrapping and hiding the ugly C callbacks.