#include"stdafx.h"
#include <stdio.h>
#include <curl/curl.h>
#include "string"
#include"stdio.h"
#include"stdlib.h"
#include "iostream"
using namespace std;
bool getUrl(char *filename)
{
CURL *curl;
CURLcode res;
FILE *fp;
if ((fp = fopen(filename, "w")) == NULL) // 返回结果用文件存储
cout << "create fail";
//system("pause");
struct curl_slist *headers = NULL;
//headers = curl_slist_append(headers, "Accept: Agent-007");
curl = curl_easy_init(); // 初始化
if (curl)
{
curl_easy_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式
curl_easy_setopt(curl, CURLOPT_PROXY, "202.112.23.167"); //代理服务器地址
curl_easy_setopt(curl, CURLOPT_PROXYPORT, 8080); //代理服务器端口
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "yxzhang:zhangyixuan12345"); //http代理认证帐号,名称:pwd的格式
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //使用http代理模式
//curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);// 改协议头
curl_easy_setopt(curl, CURLOPT_URL, "http://211.65.197.210:8080/IPCIS/activityDatabase/?IpSets=211.65.193.23:32&TableName=2018-06-12&Mode=1");
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); //将返回的http头输出到fp指向的文件
curl_easy_setopt(curl, CURLOPT_HEADERDATA, fp); //将返回的html主体数据输出到fp指向的文件
res = curl_easy_perform(curl); // 执行
if (res != 0) {
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
}
fclose(fp);
return true;
}
}
bool postUrl(char *filename)
{
CURL *curl;
CURLcode res;
FILE *fp;
if ((fp = fopen(filename, "w")) == NULL)
cout << "create fail";
system("pause");
curl = curl_easy_init();
if (curl)
{
struct curl_slist* headerlist = NULL;
// 设置表头,表头内容可能不同
headerlist = curl_slist_append(headerlist, "Content-Type:application/x-www-form-urlencoded");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);//改协议头
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); // 指定cookie文件
//curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "&prefix_name=42.244.62.215&table_name=2018-06-12"); // 指定post内容
//curl_easy_setopt(curl, CURLOPT_PROXY, "202.112.23.167:8080");
curl_easy_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式
curl_easy_setopt(curl, CURLOPT_PROXY, "202.112.23.167"); //代理服务器地址
curl_easy_setopt(curl, CURLOPT_PROXYPORT, 8080); //代理服务器端口
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "yxzhang:zhangyixuan12345"); //http代理认证帐号,名称:pwd的格式
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //使用http代理模式
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "&username=ipcis&&password=123");
curl_easy_setopt(curl, CURLOPT_URL, "http://ipdb2000.njnet.edu.cn/control_php_ipcis/login.php"); // 指定url
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
fclose(fp);
return true;
}
int main(void)
{
//getUrl("get.html");
string a = "get-ip1.html";
char* aa = (char*)a.data();
getUrl(aa);
system("pause");
}
get执行请求不到,将header定义部分都注销就好了,有时间再看一下原因。
#include <stdio.h>
#include <curl/curl.h>
#include "string"
#include"stdio.h"
#include"stdlib.h"
#include "iostream"
using namespace std;
bool getUrl(char *filename)
{
CURL *curl;
CURLcode res;
FILE *fp;
if ((fp = fopen(filename, "w")) == NULL) // 返回结果用文件存储
cout << "create fail";
//system("pause");
struct curl_slist *headers = NULL;
//headers = curl_slist_append(headers, "Accept: Agent-007");
curl = curl_easy_init(); // 初始化
if (curl)
{
curl_easy_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式
curl_easy_setopt(curl, CURLOPT_PROXY, "202.112.23.167"); //代理服务器地址
curl_easy_setopt(curl, CURLOPT_PROXYPORT, 8080); //代理服务器端口
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "yxzhang:zhangyixuan12345"); //http代理认证帐号,名称:pwd的格式
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //使用http代理模式
//curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);// 改协议头
curl_easy_setopt(curl, CURLOPT_URL, "http://211.65.197.210:8080/IPCIS/activityDatabase/?IpSets=211.65.193.23:32&TableName=2018-06-12&Mode=1");
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); //将返回的http头输出到fp指向的文件
curl_easy_setopt(curl, CURLOPT_HEADERDATA, fp); //将返回的html主体数据输出到fp指向的文件
res = curl_easy_perform(curl); // 执行
if (res != 0) {
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
}
fclose(fp);
return true;
}
}
bool postUrl(char *filename)
{
CURL *curl;
CURLcode res;
FILE *fp;
if ((fp = fopen(filename, "w")) == NULL)
cout << "create fail";
system("pause");
curl = curl_easy_init();
if (curl)
{
struct curl_slist* headerlist = NULL;
// 设置表头,表头内容可能不同
headerlist = curl_slist_append(headerlist, "Content-Type:application/x-www-form-urlencoded");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);//改协议头
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); // 指定cookie文件
//curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "&prefix_name=42.244.62.215&table_name=2018-06-12"); // 指定post内容
//curl_easy_setopt(curl, CURLOPT_PROXY, "202.112.23.167:8080");
curl_easy_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式
curl_easy_setopt(curl, CURLOPT_PROXY, "202.112.23.167"); //代理服务器地址
curl_easy_setopt(curl, CURLOPT_PROXYPORT, 8080); //代理服务器端口
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "yxzhang:zhangyixuan12345"); //http代理认证帐号,名称:pwd的格式
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //使用http代理模式
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "&username=ipcis&&password=123");
curl_easy_setopt(curl, CURLOPT_URL, "http://ipdb2000.njnet.edu.cn/control_php_ipcis/login.php"); // 指定url
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
fclose(fp);
return true;
}
int main(void)
{
//getUrl("get.html");
string a = "get-ip1.html";
char* aa = (char*)a.data();
getUrl(aa);
system("pause");
}
get执行请求不到,将header定义部分都注销就好了,有时间再看一下原因。