1 下载curl库:http://curl.haxx.se/download.html
2 下载后解压,进入curl-7.38.0\projects\Windows\VC6目录,使用vs 2010打开项目,选择DLL Release编译
3 新建curl测试项目,创建文件夹include和lib
3 进入目录curl-7.38.0\build\Win32\VC6\DLL Release将libcurl.dll和libcurl.lib分别拷贝到curl项目的include和lib目录下
4 curl测试项目属性—- C/C++ --- 预处理器– 预处理器定义 添加 CURL_STATICLIB
5 curl测试项目属性—- C/C++--- 常规–附加包含目录 添加include
6 curl测试项目属性—- 连接器 --- 常规 – 附加库目录 添加lib
7 将curl-7.38.0\include\下的curl目录拷贝到curl测试项目的include目录下
8 测试程序编写
// pachong.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <Windows.h>
#include "curl/curl.h"
#pragma comment(lib, "libcurl.lib")
#pragma comment(lib, "wldap32.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "winmm.lib")
using namespace std;
size_t write_data(char *buffer,size_t size, size_t nitems,void *outstream)
{
int written = fwrite(buffer, size, nitems, (FILE*)outstream);
return written;
}
void anaylize_data()
{
}
int _tmain(int argc, _TCHAR* argv[])
{
// 将note.xml写入myxml.xml文件里
CURL *pCurl;
FILE* pFile = fopen( "myxml.xml", "wb" );
pCurl = curl_easy_init();
curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, (void*)pFile);
curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(pCurl, CURLOPT_URL, "http://www.pc28yc.com/pre.php/");
curl_easy_perform(pCurl);
fclose(pFile);
curl_easy_cleanup( pCurl );
//将note.xml显示在终端上
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://www.pc28yc.com/pre.php/");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_global_init(CURL_GLOBAL_ALL);
}
system("pause");
//网页已经被down下来了。
//开始分析里边的数据
anaylize_data();
return 0;
}
9 运行结果