|
|
@ -1,3 +1,9 @@
|
|
|
|
|
|
|
|
/* Äîêóìåíòàöèÿ cURL:
|
|
|
|
|
|
|
|
CURLOPT_FAILONERROR:
|
|
|
|
|
|
|
|
https://curl.se/libcurl/c/CURLOPT_FAILONERROR.html
|
|
|
|
|
|
|
|
https://curl.se/libcurl/c/libcurl-errors.html#CURLEHTTPRETURNEDERROR
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
#include "histogram.h"
|
|
|
|
#include "histogram.h"
|
|
|
@ -57,13 +63,23 @@ download(const string& address)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -----âàð 17
|
|
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L); //Ïðåâðàùàåò HTTP-îøèáêè (ñòàòóñû 4xx è 5xx) â îøèáêè cURL
|
|
|
|
|
|
|
|
//-------
|
|
|
|
|
|
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
|
|
|
|
|
|
|
|
|
|
|
CURLcode res = curl_easy_perform(curl);
|
|
|
|
CURLcode res = curl_easy_perform(curl);
|
|
|
|
if (res != CURLE_OK)
|
|
|
|
if (res != CURLE_OK)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cerr << "cURL error: " << curl_easy_strerror(res) << endl;
|
|
|
|
// -----âàð 17
|
|
|
|
|
|
|
|
if (res == CURLE_HTTP_RETURNED_ERROR) {
|
|
|
|
|
|
|
|
cerr << "HTTP Error: Server returned 4xx/5xx status code for URL: " << address << endl; //Òî÷å÷íî îáðàáàòûâàåì ñëó÷àé, êîãäà ñåðâåð âåðíóë îøèáêó
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cerr << "cURL error (" << res << "): " << curl_easy_strerror(res) << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
exit(1);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|