libcurl.lib(或libcurl.so,unix下面尽量实时编译,并且要注意系统版本(32 or 64))是跨平台解析http请求数据的动态库,使用起来非常方便。
以在Windows下使用为例。
在使用前,要将libcurl库相关的头文件添加至附加包含目录。
引用相关库:
#pragma comment(lib,"ws2_32.lib") #pragma comment(lib,"winmm.lib") #pragma comment(lib,"wldap32.lib") #pragma comment(lib,"libcurl.lib")
在预处理器定义中添加:BUILDING_LIBCURL;HTTP_ONLY
下面就是直接使用libcurl.lib的示例了。
HttpHelper.h
#ifndef HTTPHELPER
#define HTTPHELPER
#include "curl.h"
#include "easy.h"
#include "curlbuild.h"
#include "curlrules.h"
using namespace std;
#include <vector>
//http数据类
class TileInfo
{
public:
TileInfo()
{
data=NULL;
}
~TileInfo()
{
if (data)
{
delete[] data;
data=NULL;
}
}
char* data;
long dataSize;
}