{"id":14989939,"url":"https://github.com/josephp91/curlcpp","last_synced_at":"2025-05-14T05:10:43.056Z","repository":{"id":13001044,"uuid":"15680237","full_name":"JosephP91/curlcpp","owner":"JosephP91","description":"An object oriented C++ wrapper for CURL (libcurl)","archived":false,"fork":false,"pushed_at":"2025-02-06T07:52:49.000Z","size":1353,"stargazers_count":643,"open_issues_count":9,"forks_count":174,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-04-14T12:58:23.104Z","etag":null,"topics":["c-plus-plus","cpp","cross-platform","curl","lcurlcpp-lcurl","libcurl","network-requests","networking","receiver"],"latest_commit_sha":null,"homepage":"https://josephp91.github.io/curlcpp","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JosephP91.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://www.bitcoinqrcodemaker.com/pay/?type=2\u0026style=bitcoin\u0026color=1\u0026border=4\u0026address=bc1qej7q0wuh3f944v9yx3s7a2ltn8aj6wyrddyc62"}},"created_at":"2014-01-06T17:28:11.000Z","updated_at":"2025-04-11T08:22:31.000Z","dependencies_parsed_at":"2024-01-03T01:19:55.245Z","dependency_job_id":"fb32c69d-61c8-4e2f-8650-15a1a03e4f90","html_url":"https://github.com/JosephP91/curlcpp","commit_stats":{"total_commits":266,"total_committers":49,"mean_commits":5.428571428571429,"dds":"0.47744360902255634","last_synced_commit":"f4b87d02725065536bf6620c29aa8c13e15a1993"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosephP91%2Fcurlcpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosephP91%2Fcurlcpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosephP91%2Fcurlcpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosephP91%2Fcurlcpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JosephP91","download_url":"https://codeload.github.com/JosephP91/curlcpp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254076850,"owners_count":22010611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","cpp","cross-platform","curl","lcurlcpp-lcurl","libcurl","network-requests","networking","receiver"],"created_at":"2024-09-24T14:19:11.608Z","updated_at":"2025-05-14T05:10:42.982Z","avatar_url":"https://github.com/JosephP91.png","language":"C++","funding_links":["https://www.bitcoinqrcodemaker.com/pay/?type=2\u0026style=bitcoin\u0026color=1\u0026border=4\u0026address=bc1qej7q0wuh3f944v9yx3s7a2ltn8aj6wyrddyc62"],"categories":[],"sub_categories":[],"readme":"curlcpp\n=======\n\nAn object-oriented C++ wrapper for cURL tool\n\nIf you want to know a bit more about cURL and libcurl, you should go on the official website http://curl.haxx.se/\n\nDonate\n======\n\nHelp me to improve this project!\n\n\u003ca href=\"https://www.bitcoinqrcodemaker.com/pay/?type=2\u0026amp;style=bitcoin\u0026amp;color=1\u0026amp;border=4\u0026amp;address=bc1qn99uh5a7h7mezd9j3grrc2hrr376n25z5dk8er\" target=\"_blank\"\u003e\u003cimg src=\"https://www.bitcoinqrcodemaker.com/donate_button.png\" border=\"0\" width=\"150\" height=\"36\" alt=\"Donate button\" title=\"Donate\" /\u003e\u003c/a\u003e\n\n\n\nCompile and link manually\n=========================\n\nStandalone (static library)\n----------\n\n```bash\ncd build\ncmake ..\nmake\n```\n\nStandalone (dynamic/shared library)\n----------\n\n```bash\ncd build\ncmake .. -DBUILD_SHARED_LIBS=SHARED\nmake\n```\n\n**Note:** cURL \u003e= 7.34.0 is required.\n\nWhen linking curlcpp to your application don't forget to also link `curl`. Example:\n\n```bash\ng++ -std=c++11 example.cpp -I/usr/local/include/curlcpp/ -lcurlcpp -lcurl \n```\n\nSubmodule\n---------\n\nWhen using a git submodule and CMake-buildsystem, add the following lines to your `CMakeLists.txt`:\n\n```\nADD_SUBDIRECTORY(ext/curlcpp) # Change `ext/curlcpp` to a directory according to your setup\nINCLUDE_DIRECTORIES(${CURLCPP_SOURCE_DIR}/include)\n```\n\n\nInstall via Homebrew\n====================\n\ncurlcpp is now available also via homebrew package manager:\n\n```bash\nbrew install curlcpp\n```\n\n\nExamples\n========\n\nHere are some usage examples. You will find more examples in the test folder!\n\nHere's an example of a simple HTTP request to get google web page, using the curl_easy interface:\n\n* ### Simple request\n\n`````c++\n#include \"curlcpp/curl_easy.h\"\n\nusing curl::curl_easy;\nusing curl::curl_easy_exception;\nusing curl::curlcpp_traceback;\n\n/**\n * This example shows how to make a simple request with curl.\n */\nint main() {\n    // Easy object to handle the connection.\n    curl_easy easy;\n\n    // Add some options.\n    easy.add\u003cCURLOPT_URL\u003e(\"http://\u003cyour_url_here\u003e\");\n    easy.add\u003cCURLOPT_FOLLOWLOCATION\u003e(1L);\n\n    try {\n        easy.perform();\n    } catch (curl_easy_exception \u0026error) {\n    \t// If you want to print the last error.\n        std::cerr\u003c\u003cerror.what()\u003c\u003cstd::endl;\n    }\n    return 0;\n}\n`````\n\n* ### Extract session information\n\nIf you want to get information about the current curl session, you could do:\n\n`````c++\n#include \"curlcpp/curl_easy.h\"\n#include \"curlcpp/curl_ios.h\"\n#include \"curlcpp/curl_exception.h\"\n\nusing std::ostringstream;\n\nusing curl::curl_easy;\nusing curl::curl_easy_exception;\nusing curl::curlcpp_traceback;\nusing curl::curl_ios;\n\n/**\n * This example shows how to use the easy interface and obtain \n * information about the current session.\n */\nint main(int argc, const char **argv) {\n    // Let's declare a stream\n    ostringstream stream;\n\n    // We are going to put the request's output in the previously declared stream\n    curl_ios\u003costringstream\u003e ios(stream);\n\n    // Declaration of an easy object\n    curl_easy easy(ios);\n\n    // Add some option to the curl_easy object.\n    easy.add\u003cCURLOPT_URL\u003e(\"http://\u003cyour_url_here\u003e\");\n    easy.add\u003cCURLOPT_FOLLOWLOCATION\u003e(1L);\n\n    try {\n        easy.perform();\n\n\t\t// Retrieve information about curl current session.\n\t\tauto x = easy.get_info\u003cCURLINFO_CONTENT_TYPE\u003e();\n\n\t\t/**\n\t\t * get_info returns a curl_easy_info object. With the get method we retrieve\n\t\t * the std::pair object associated with it: the first item is the return code of the\n\t\t * request. The second is the element requested by the specified libcurl macro.\n\t\t */\n\t\tstd::cout\u003c\u003cx.get()\u003c\u003cstd::endl;\n\n    } catch (curl_easy_exception \u0026error) {\n\t\t// If you want to print the last error.\n\t\tstd::cerr\u003c\u003cerror.what()\u003c\u003cstd::endl;\n\n\t\t// If you want to print the entire error stack you can do\n\t\terror.print_traceback();\n    }\n    return 0;\n}\n`````\n\n* ### HTTP Post\n\nHere's instead, the creation of an HTTPS POST login form:\n\n`````c++\n#include \u003cstring\u003e\n\n#include \"curlcpp/curl_easy.h\"\n#include \"curlcpp/curl_pair.h\"\n#include \"curlcpp/curl_form.h\"\n#include \"curlcpp/curl_exception.h\"\n\nusing std::string;\n\nusing curl::curl_form;\nusing curl::curl_easy;\nusing curl::curl_pair;\nusing curl::curl_easy_exception;\nusing curl::curlcpp_traceback;\n\nint main(int argc, const char * argv[]) {\n    curl_form form;\n    curl_easy easy;\n\n    // Forms creation\n    curl_pair\u003cCURLformoption,string\u003e name_form(CURLFORM_COPYNAME,\"user\");\n    curl_pair\u003cCURLformoption,string\u003e name_cont(CURLFORM_COPYCONTENTS,\"you username here\");\n    curl_pair\u003cCURLformoption,string\u003e pass_form(CURLFORM_COPYNAME,\"passw\");\n    curl_pair\u003cCURLformoption,string\u003e pass_cont(CURLFORM_COPYCONTENTS,\"your password here\");\n    \n    try {\n        // Form adding\n        form.add(name_form,name_cont);\n        form.add(pass_form,pass_cont);\n        \n        // Add some options to our request\n        easy.add\u003cCURLOPT_URL\u003e(\"http://\u003cyour_url_here\u003e\");\n        easy.add\u003cCURLOPT_SSL_VERIFYPEER\u003e(false);\n        easy.add\u003cCURLOPT_HTTPPOST\u003e(form.get());\n        // Execute the request.\n        easy.perform();\n\n    } catch (curl_easy_exception \u0026error) {\n        // If you want to get the entire error stack we can do:\n        curlcpp_traceback errors = error.get_traceback();\n        // Otherwise we could print the stack like this:\n        error.print_traceback();\n    }\n    return 0;\n}\n`````\n\n* ### Store response in a file\n\nAnd if we would like to put the returned content in a file? Nothing easier than:\n\n`````c++\n#include \u003ciostream\u003e\n#include \u003costream\u003e\n#include \u003cfstream\u003e\n\n#include \"curlcpp/curl_easy.h\"\n#include \"curlcpp/curl_ios.h\"\n#include \"curlcpp/curl_exception.h\"\n\nusing std::cout;\nusing std::endl;\nusing std::ostream;\nusing std::ofstream;\n\nusing curl::curl_easy;\nusing curl::curl_ios;\nusing curl::curl_easy_exception;\nusing curl::curlcpp_traceback;\n\nint main(int argc, const char * argv[]) {\n    // Create a file\n    ofstream myfile;\n    myfile.open (\"/path/to/your/file\");\n    \n    // Create a curl_ios object to handle the stream\n    curl_ios\u003costream\u003e writer(myfile);\n    // Pass it to the easy constructor and watch the content returned in that file!\n    curl_easy easy(writer);\n    \n    // Add some option to the easy handle\n    easy.add\u003cCURLOPT_URL\u003e(\"http://\u003cyour_url_here\u003e\");\n    easy.add\u003cCURLOPT_FOLLOWLOCATION\u003e(1L);\n    try {\n        // Execute the request\n        easy.perform();\n\n    } catch (curl_easy_exception \u0026error) {\n\t\t// If you want to print the last error.\n\t\tstd::cerr\u003c\u003cerror.what()\u003c\u003cstd::endl;\n\n\t\t// If you want to print the entire error stack you can do\n\t\terror.print_traceback();\n    }\n    myfile.close();\n    return 0;\n}\n`````\n\n* ### Store response in a variable\n\nNot interested in files? So let's put the request's output in a variable!\n\n`````c++\n#include \u003ciostream\u003e\n#include \u003costream\u003e\n\n#include \"curlcpp/curl_easy.h\"\n#include \"curlcpp/curl_form.h\"\n#include \"curlcpp/curl_ios.h\"\n#include \"curlcpp/curl_exception.h\"\n\nusing std::cout;\nusing std::endl;\nusing std::ostringstream;\n\nusing curl::curl_easy;\nusing curl::curl_ios;\nusing curl::curl_easy_exception;\nusing curl::curlcpp_traceback;\n\nint main() {\n    // Create a stringstream object\n    ostringstream str;\n    // Create a curl_ios object, passing the stream object.\n    curl_ios\u003costringstream\u003e writer(str);\n    \n    // Pass the writer to the easy constructor and watch the content returned in that variable!\n    curl_easy easy(writer);\n    // Add some option to the easy handle\n    easy.add\u003cCURLOPT_URL\u003e(\"http://\u003cyour_url_here\u003e\");\n    easy.add\u003cCURLOPT_FOLLOWLOCATION\u003e(1L);\n\n    try {\n        easy.perform();\n\n        // Let's print the stream content\n        cout\u003c\u003cstr.str()\u003c\u003cendl;\n\n    } catch (curl_easy_exception \u0026error) {\n\t\t// If you want to print the last error.\n\t\tstd::cerr\u003c\u003cerror.what()\u003c\u003cstd::endl;\n\n\t\t// If you want to print the entire error stack you can do\n\t\terror.print_traceback();\n    }\n    return 0;\n}\n`````\n\n* ### Sender/Receiver\n\nI have implemented a sender and a receiver to make it easy to use send/receive without handling\nbuffers. For example, a very simple send/receiver would be:\n\n`````c++\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n\n#include \"curlcpp/curl_easy.h\"\n#include \"curlcpp/curl_form.h\"\n#include \"curlcpp/curl_pair.h\"\n#include \"curlcpp/curl_receiver.h\"\n#include \"curlcpp/curl_exception.h\"\n#include \"curlcpp/curl_sender.h\"\n\nusing std::cout;\nusing std::endl;\nusing std::string;\n\nusing curl::curl_form;\nusing curl::curl_easy;\nusing curl::curl_sender;\nusing curl::curl_receiver;\nusing curl::curl_easy_exception;\nusing curl::curlcpp_traceback;\n\nint main(int argc, const char * argv[]) {\n    // Simple request\n    string request = \"GET / HTTP/1.0\\r\\nHost: example.com\\r\\n\\r\\n\";\n    // Creation of easy object.\n    curl_easy easy;\n    try {\n        easy.add\u003cCURLOPT_URL\u003e(\"http://\u003cyour_url_here\u003e\");\n        // Just connect\n        easy.add\u003cCURLOPT_CONNECT_ONLY\u003e(true);\n        // Execute the request.\n        easy.perform();\n\n    } catch (curl_easy_exception \u0026error) {\n        // If you want to get the entire error stack we can do:\n        curlcpp_traceback errors = error.get_traceback();\n        // Otherwise we could print the stack like this:\n        error.print_traceback();\n    }\n    \n    // Creation of a sender. You should wait here using select to check if socket is ready to send.\n    curl_sender\u003cstring\u003e sender(easy);\n    sender.send(request);\n    // Prints che sent bytes number.\n    cout\u003c\u003c\"Sent bytes: \"\u003c\u003csender.get_sent_bytes()\u003c\u003cendl;\n\n    for(;;) {\n        // You should wait here to check if socket is ready to receive\n        try {\n            // Create a receiver\n            curl_receiver\u003cchar, 1024\u003e receiver;\n            // Receive the content on the easy handler\n            receiver.receive(easy);\n            // Prints the received bytes number.\n            cout\u003c\u003c\"Receiver bytes: \"\u003c\u003creceiver.get_received_bytes()\u003c\u003cendl;\n\n        } catch (curl_easy_exception \u0026error) {\n            // If any errors occur, exit from the loop\n            break;\n        }\n    }\n    return 0;\n}\n`````\n\n* ### Multi interface example\n\nThe following example shows ho to use the curl MULTI interface.\n\nI have implemented a sender and a receiver to make it easy to use send/receive without handling\nbuffers. For example, a very simple send/receiver would be:\n\n`````c++\n#include \u003ciostream\u003e\n#include \u003costream\u003e\n\n#include \"curlcpp/curl_easy.h\"\n#include \"curlcpp/curl_multi.h\"\n#include \"curlcpp/curl_ios.h\"\n\nusing curl::curl_easy;\nusing curl::curl_multi;\nusing curl::curl_ios;\nusing curl::curl_easy_exception;\nusing curl::curlcpp_traceback;\n\n/**\n * This example shows how to make multiple requests\n * using curl_multi interface.\n */\nint main() {\n    std::vector\u003cstd::string\u003e urls;\n    urls.emplace_back(\"https://google.com\");\n    urls.emplace_back(\"https://facebook.com\");\n    urls.emplace_back(\"https://linkedin.com\");\n\n    // Create a vector of curl easy handlers.\n    std::vector\u003ccurl_easy\u003e handlers;\n\n    // Create a vector of curl streams.\n    std::vector\u003ccurl_ios\u003cstd::ostringstream\u003e\u003e streams;\n\n    // Create the curl easy handler and associated the streams with it.\n    for (const auto \u0026 url : urls) {\n        auto *output_stream = new std::ostringstream;\n        curl_ios\u003cstd::ostringstream\u003e curl_stream(*output_stream);\n\n        curl_easy easy(curl_stream);\n        easy.add\u003cCURLOPT_URL\u003e(url.c_str());\n        easy.add\u003cCURLOPT_FOLLOWLOCATION\u003e(1L);\n\n        streams.emplace_back(curl_stream);\n        handlers.emplace_back(easy);\n    }\n\n    // Create a map of curl pointers to output streams.\n    std::unordered_map\u003cCURL*, curl_ios\u003cstd::ostringstream\u003e*\u003e easy_streams;\n    for (int i = 0; i \u003c handlers.size(); ++i) {\n        easy_streams[handlers.at(i).get_curl()] = (curl_ios\u003cstd::ostringstream\u003e*)\u0026streams.at(i);\n    }\n\n    // Add all the handlers to the curl multi object.\n    curl_multi multi;\n    multi.add(handlers);\n\n    try {\n        // Start the transfers.\n        multi.perform();\n\n        // Until there are active transfers, call the perform() API.\n        while (multi.get_active_transfers()) {\n            multi.perform();\n\n            // Extracts the first finished request.\n            std::unique_ptr\u003ccurl_multi::curl_message\u003e message = multi.get_next_finished();\n            if (message != nullptr) {\n                const curl_easy *handler = message-\u003eget_handler();\n\n                // Get the stream associated with the curl easy handler.\n                curl_ios\u003cstd::ostringstream\u003e stream_handler = *easy_streams[handler-\u003eget_curl()];\n\n                auto content = stream_handler.get_stream()-\u003estr();\n                auto url = handler-\u003eget_info\u003cCURLINFO_EFFECTIVE_URL\u003e();\n                auto response_code = handler-\u003eget_info\u003cCURLINFO_RESPONSE_CODE\u003e();\n                auto content_type = handler-\u003eget_info\u003cCURLINFO_CONTENT_TYPE\u003e();\n                auto http_code = handler-\u003eget_info\u003cCURLINFO_HTTP_CODE\u003e();\n\n                std::cout \u003c\u003c \"CODE: \" \u003c\u003c response_code.get()\n                          \u003c\u003c \", TYPE: \" \u003c\u003c content_type.get()\n                          \u003c\u003c \", HTTP_CODE: \" \u003c\u003c http_code.get()\n                          \u003c\u003c \", URL: \" \u003c\u003c url.get()\n                          \u003c\u003c \", CONTENT: \" \u003c\u003c content.substr(0, 10) + \" ... \"\n                          \u003c\u003c std::endl;\n            }\n        }\n\n        // Free the memory allocated for easy streams.\n        for (auto stream : streams) {\n            delete stream.get_stream();\n        }\n\n    } catch (curl_easy_exception \u0026error) {\n        // If you want to print the last error.\n        std::cerr\u003c\u003cerror.what()\u003c\u003cstd::endl;\n    }\n    return 0;\n}\n`````\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosephp91%2Fcurlcpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosephp91%2Fcurlcpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosephp91%2Fcurlcpp/lists"}