C语言代码示例
发布时间:2023-03-27 21:35
#include
#include
#include
#include "curl/curl.h"
using namespace std;
static size_t WriteMemoryCallback(void* ptr, size_t size, size_t nmemb, void* stream) {
size_t nsize = size * nmemb;
string* strdata = (string*)stream;
if (strdata)
strdata->append((const char*)ptr, nsize);
return nsize;
}
void Proxy(string& resp) {
CURL* curl = curl_easy_init();
CURLcode res;
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://ip.cn/api/index?ip=&type=0");
curl_easy_setopt(curl, CURLOPT_PROXY, "http://代理IP:端口号");
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "请改成您的Key:请改成您的AuthPwd");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &resp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res != CURLE_OK) {
fprintf(stderr, "request failed: %s\n", curl_easy_strerror(res));
}
}
}
int main() {
string response;
Proxy(response);
cout << response << endl;
return 0;
}
相关文章