#include
#include
size_t writeCallback(char* ptr, size_t size, size_t nmemb, void* userdata) {
((std::string*)userdata)->append((char*)ptr, size * nmemb);
return size * nmemb;
}
int main() {
CURL* curl = curl_easy_init();
// 获取代理IP
CURLcode res;
std::string proxyIpPort;
curl_easy_setopt(curl, CURLOPT_URL, "http://api.ip.data5u.com/dynamic/get.html?order=你的提取码&sep=3");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &proxyIpPort);
res = curl_easy_perform(curl);
// 设置代理
std::string ip = proxyIpPort.substr(0, proxyIpPort.find(':'));
std::string port = proxyIpPort.substr(proxyIpPort.find(':')+1);
curl_easy_setopt(curl, CURLOPT_PROXY, ip.c_str());
curl_easy_setopt(curl, CURLOPT_PROXYPORT, std::stoi(port));
// 获取目标网页
std::string html;
curl_easy_setopt(curl, CURLOPT_URL, "http://www.bing.com");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &html);
res = curl_easy_perform(curl);
std::cout << html << std::endl;
curl_easy_cleanup(curl);
}