35 static size_t write_callback(
void* contents,
size_t size,
size_t nmemb,
void* userp )
37 size_t realsize = size * nmemb;
39 std::string* p = (std::string*) userp;
41 p->append( (
const char*) contents, realsize );
73 curl_easy_cleanup(
m_CURL );
87 CURLcode res = curl_easy_perform(
m_CURL );
91 std::string msg =
"curl_easy_perform()=";
92 msg += (int)res; msg +=
" "; msg +=
GetErrorText( res ).c_str();
100 std::string header = aName +
':' + aValue;
107 return curl_easy_setopt(
m_CURL, (CURLoption)aOption, aArg );
113 return curl_easy_strerror( (CURLcode)aCode );
119 if( setOption<const char*>( CURLOPT_USERAGENT, aAgent.c_str() ) == CURLE_OK )
129 if( setOption<const char *>( CURLOPT_URL, aURL.c_str() ) == CURLE_OK )
139 if( setOption<long>( CURLOPT_FOLLOWLOCATION , (aFollow ? 1 : 0) ) == CURLE_OK )
149 char* escaped = curl_easy_escape(
m_CURL, aUrl.c_str(), aUrl.length() );
151 std::string ret( escaped );
152 curl_free( escaped );
bool SetUserAgent(const std::string &aAgent)
Function SetUserAgent sets the request user agent.
static size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp)
void Perform()
Function perform equivalent to curl_easy_perform.
bool SetFollowRedirects(bool aFollow)
Function SetFollowRedirects enables the following of HTTP(s) and other redirects, by default curl doe...
static void Init()
Function Init calls curl_global_init for the application.
int setOption(int aOption, T aArg)
Function setOption sets a curl option, only supports single parameter curl options.
std::string Escape(const std::string &aUrl)
Escapes a string for use as a URL.
const std::string GetErrorText(int aCode)
Function GetErrorText fetches CURL's "friendly" error string for a given error code.
bool SetURL(const std::string &aURL)
Function SetURL sets the request URL.
void SetHeader(const std::string &aName, const std::string &aValue)
Function SetHeader sets an arbitrary header for the HTTP(s) request.
#define THROW_IO_ERROR(msg)