from http://blog.csdn.net/hwz119/article/details/1591920 2007.04 Libcurl为一个免费开源的,客户端url传输库,支持FTP,FTPS,TFTP,HTTP,HTTPS,GOPHER,TELNET,DICT,FILE和LDAP,跨平台,支持Windows,Unix,Linux等,线程安全,支持Ipv6。并且易于使用。 从http://curl./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. 或者http://www./ 下载。 如果需要编译其他版本,可查看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."); res = curl_easy_perform(curl); if(CURLE_OK == res) { char *ct; /* ask for the content-type */ /* http://curl./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; } |
|