原文見http://blog.vckbase.com/michael/archive/2005/11/29/15426.aspx
Libcurl為一個免費開源的,客戶端url傳輸庫,支持FTP,FTPS,TFTP,HTTP,HTTPS,GOPHER,TELNET,DICT,FILE和LDAP,跨平臺,支持Windows,Unix,Linux等,線程安全,支持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
;
}
已知
bugs
不支持SOCKS4。
SOCKS5實現有缺陷,導致必須設置用戶和密碼。
連接
proxy
過程不能設置超時。
posted on 2006-07-26 12:04
四海 閱讀(1079)
評論(0) 編輯 收藏 引用 所屬分類:
類庫/框架