C语言代码示例
发布时间:2022-07-03 00:12
#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://myip.ipip.net");
curl_easy_setopt(curl, CURLOPT_PROXY, "http://219.151.125.106:31615");
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "895314XY:24D6YB309ZCB");
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;
}
相关文章