How to: 如何操作 #include <iostream> #include <curl/curl.h> size_t callback(void *contents, size_t size, size_t nmemb, std::string s) { size_t newLength = size * nmemb; try { s->append((char)contents, newLength); } catch(std::bad_alloc &e) { // Handle memory problem return 0; } return newLength; } int main() { CURL *curl; CURLcode res; std::string response; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); res = curl_easy_perform(curl);