CurlEasy::CurlEasy(CurlOption ops): m_ops(ops) { if ((m_curl = curl_easy_init()) == NULL) throw CurlException(EC_CURL_FAILED_INIT); curl_easy_setopt(m_curl, CURLOPT_NOSIGNAL, 1); // Default time-out values SetConnectionTimeOut(60); SetTimeOut(120); }
void fetchUrl(const std::string& url, std::string* result) { CurlSessionPtr session = CurlSessionFactory::getInstance().createSession(); if (session) { curl_easy_setopt(session.get(), CURLOPT_URL, url.c_str()); curl_easy_setopt(session.get(), CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(session.get(), CURLOPT_WRITEFUNCTION, writeDataCallback); curl_easy_setopt(session.get(), CURLOPT_WRITEDATA, result); CURLcode res = curl_easy_perform(session.get()); if (res != CURLE_OK) { std::ostringstream os; os << "CurlTools: can not perform request to \"" << url << "\". Error code: " << res; throw CurlException(os.str()); } } }
// OPERATIONS inline void _CheckError(CURLcode err, const std::string& msg) { if (err != CURLE_OK) { throw CurlException(err, std::string("Failed ") + msg); } }