48 CURL *curl = curl_easy_init();
50 resp.
error =
"curl_easy_init failed";
54 curl_slist *headers =
nullptr;
55 if (!req.
body.empty())
56 headers = curl_slist_append(headers,
"Content-Type: application/json");
60 curl_easy_setopt(curl, CURLOPT_URL, req.
url.c_str());
62 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf);
63 curl_easy_setopt(curl, CURLOPT_TIMEOUT,
65 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT,
67 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
68 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
69 curl_easy_setopt(curl, CURLOPT_USERAGENT,
"products_log/1.0");
73 curl_easy_setopt(curl, CURLOPT_USERPWD, userpwd.c_str());
76 if (req.
method ==
"POST") {
77 curl_easy_setopt(curl, CURLOPT_POST, 1L);
78 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req.
body.c_str());
79 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,
80 static_cast<long>(req.
body.size()));
83 const CURLcode rc = curl_easy_perform(curl);
85 resp.
error = curl_easy_strerror(rc);
89 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
90 resp.
status =
static_cast<int>(http_code);
94 curl_slist_free_all(headers);
95 curl_easy_cleanup(curl);