-
#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: %sn", curl_easy_strerror(res));
-
}
-
}
-
}
-
int main()
{
-
string response;
-
Proxy(response);
-
cout
-
return
0;
-
}
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net