в:17
Этот коммит содержится в:
18
main.cpp
18
main.cpp
@@ -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 <vector>
|
||||
#include "histogram.h"
|
||||
@@ -57,13 +63,23 @@ download(const string& address)
|
||||
{
|
||||
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_WRITEDATA, &buffer);
|
||||
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
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);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user