#include#include int main() { CURL *curl; CURLcode res; std::string url = "https://example.com"; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); res = curl_easy_perform(curl); if (res != CURLE_OK) { std::cerr << "Error: " << curl_easy_strerror(res) << std::endl; } curl_easy_cleanup(curl); } return 0; }
#includeThis example shows how to make a POST request to the URL specified in the code. The data to be posted is specified using a string, and is sent using the CURLOPT_POSTFIELDS option. The CURLOPT_POST option is set to 1 to indicate that this is a POST request. Based on the #include statements in both examples, the package library being used is likely the default libcURL library that comes with most C++ compilers.#include #include int main() { CURL *curl; CURLcode res; std::string url = "https://example.com"; std::string data = "name=test&city=Seattle"; curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); curl_easy_setopt(curl, CURLOPT_POST, 1L); res = curl_easy_perform(curl); if (res != CURLE_OK) { std::cerr << "Error: " << curl_easy_strerror(res) << std::endl; } curl_easy_cleanup(curl); } return 0; }