C语言代码示例

发布时间:2025-09-26 09:52:03  阅读:183

#include <iostream>
#include <algorithm>
#include <cstring>
#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://test.ipw.cn");
        // 如果上面目标站不可用,请使用ip.sb、ipinfo.io、ip-api.com、64.ipcheck.ing
        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;
}
免费试用

客服

在线客服:

:584170010

:18200508160

:service@wukongdaili.com

售后客服

技术客服