libwolfram20

◆ DownloadURL()

bool WAEngine::DownloadURL ( std::string  url,
std::string *  readBuffer 
)
static

Given an url it downloads its HTML contents.

Parameters
[in]urlURL to download
[out]readBufferDownloaded website
Return values
trueAll OK
falseError while downloading
83 {
84 CURL *curl = nullptr;
85 CURLcode res;
86
87 readBuffer->clear();
88
89 curl = curl_easy_init();
90 if(curl == nullptr) {
91 std::cerr << "CURL init error!" << std::endl;
92 return false;
93 }
94
95 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
96 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
97 curl_easy_setopt(curl, CURLOPT_WRITEDATA, readBuffer);
98 curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
99 res = curl_easy_perform(curl);
100
101 curl_easy_cleanup(curl);
102
103 if (res != CURLE_OK) {
104 std::cerr << "Response code " << res << std::endl;
105 return false;
106 }
107
108 return true;
109}
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
Function called by CUrl on DownloadURL.
Definition: WAEngine.cpp:69