Libcurl 简明使用指南

 

Libcurl 简明使用指南

Libcurl为一个免费开源的,客户端url传输库,支持FTPFTPSTFTPHTTPHTTPSGOPHERTELNETDICTFILELDAP,跨平台,支持WindowsUnixLinux等,线程安全,支持Ipv6。并且易于使用。

http://curl.haxx.se/libcurl/

 

http://curl.haxx.se/libcurl/ 下载一个稳定的版本,注意选择OS

 

编译libcurl

下载下来的是源码包,需要编译。

解压zip文件,进入curl-7.14.0/lib目录(我下载的是7.14.0)。

编译Debug版本。新建一个批处理bat文件,如buildDebug.bat,内容如下:

call "C:/Program Files/Microsoft Visual Studio/VC98/Bin/vcvars32.bat"

set CFG=debug-dll-ssl-dll-zlib-dll

set OPENSSL_PATH=E:/SSL/openssl-0.9.7e

set ZLIB_PATH=E:/zip/zlib123

nmake -f Makefile.vc6

 

其输出:libcurld_imp.lib, libcurld.dll

 

编译Release版本。新建一个批处理文件BuildRelease.bat,内容如下:

call "C:/Program Files/Microsoft Visual Studio/VC98/Bin/vcvars32.bat"

set CFG=release-dll-ssl-dll-zlib-dll

set OPENSSL_PATH=E:/SSL/openssl-0.9.7e

set ZLIB_PATH=E:/zip/zlib123

nmake -f Makefile.vc6

 

其输出:libcurl_imp.lib, libcurl.dll

 

上面编译的是libcurl dll,使用OpenSSL Dll版本和Zlib Dll版本。如果没有,可以从www.openssl.org 或者http://www.zlib.net/ 下载。

如果需要编译其他版本,可查看Makefile.vc6,设定相应的CFG 参数即可。

 

商业软件使用libcurl时,只需要包含其copywrite声明即可。

 

Sample

 

#include  < stdio.h >
#include 
" ../curl-7.14.0/include/curl/curl.h "
#pragma comment(lib, 
" ../curl-7.14.0/lib/libcurl_imp.lib " )

int  main( void )
{
  curl 
= curl_easy_init();
  
if(curl) {

    CURLcode res;    
    res 
= curl_easy_setopt(curl, CURLOPT_PROXY, "Test-pxy08:8080");
    res 
= curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
    res 
= curl_easy_setopt(curl, CURLOPT_URL, "http://www.vckbase.com");
    res 
= curl_easy_perform(curl);

    
if(CURLE_OK == res) {
      
char *ct;
      
/* ask for the content-type */
      
/* http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html */
      res 
= curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);

      
if((CURLE_OK == res) && ct)
        printf(
"We received Content-Type: %s ", ct);
    }


    
/* always cleanup */
    curl_easy_cleanup(curl);
  }

  
return 0;
}
  • 0
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值