编译库和程序
./configure --prefix=/opt/libcurl --without-ssl --without-libpsl
make && make install
g++ -std=c++11 -I./include -L./lib -lcurl curlTestv2.cp
curlTestv2.cp:
#include <curl/curl.h>
#include <iostream>
#include <memory>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>
#include <mutex>
class CurlHttp {
public:
class RequestBuilder;
CurlHttp() {
static std::once_flag curlGlobalInitFlag;
std::call_once(curlGlobalInitFlag, []() {
curl_global_init(CURL_GLOBAL_ALL);
});
}
~CurlHttp() = default;
CurlHttp(const CurlHttp&) = delete;
CurlHttp& operator=(const CurlHttp&) = delete;
static size_t writeCallback(char* ptr, size_t size, size_t nmemb, std::ostringstream* stream) {
stream->write(ptr, size * nmemb