Libcurl为一个免费开源的,客户端url传输库,支持FTP,FTPS,TFTP,HTTP,HTTPS,GOPHER,TELNET,DICT,FILE和LDAP,跨平台,支持Windows,Unix,Linux等,线程安全,支持Ipv6。并且易于使用。
开发工具:vs2010
环境:控制台程序
操作系统:win7操作系统
配置如下:
1、库头文件的引入
2、lib库的引入
3、依赖项的引入
4、预处理的定义
4
库的使用:
代码如下:
// NMakeDemo.cpp : 定义控制台应用程序的入口点。
***************************************************************************/
#include <stdio.h>
#include <iostream>
#include <curl/curl.h>
using namespace std;
int main(void)
{
CURL *curl;
CURLcode res;
// 初始化libcurl
res = curl_global_init(CURL_GLOBAL_WIN32);
if (CURLE_OK != res)
{
return -1;
}
cout<<curl_version()<<endl;
curl = curl_easy_init();
if(curl) {
// curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
curl_easy_setopt(curl, CURLOPT_URL, "file:///C:/Users/zfs/Desktop/WebAudio/WebAudio/readme.txt");
/* example.com is redirected, so we tell libcurl to follow redirection */
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
/***************************************************************************/
运行如下: