Libcurl 簡明使用指南
Libcurl為一個免費開源的,客戶端url傳輸庫,支持FTP,FTPS,TFTP,HTTP,HTTPS,GOPHER,TELNET,DICT,FILE和LDAP,跨平臺,支持Windows,Unix,Linux等,線程安全,支持Ipv6。并且易于使用。
從http://curl.haxx.se/libcurl/ 下載一個穩定的版本,注意選擇OS。
編譯libcurl
下載下來的是源碼包,需要編譯。
解壓zip文件,進入curl-
編譯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-
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-
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-
#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;
}
posted on 2009-03-13 12:05 肥仔 閱讀(6257) 評論(2) 編輯 收藏 引用 所屬分類: 網絡編程