curl(CommandLine Uniform Resource Locator)主要功能就是用不同的协议连接和沟通不同的服务器,相当封装了的socket。
libcurl支持http, https, ftp, gopher, telnet, dict, file, 和ldap 协议。libcurl同样支持HTTPS证书授权,HTTP POST, HTTP PUT, FTP 上传(当然你也可以使用PHP的ftp扩展), HTTP基本表单上传,代理,cookies和用户认证。
curl网站:
libcurl
下载libcurl:
获取curl-7.86.0.tar.gz文件。
解压缩curl-7.86.0.tar.gz文件。
进入curl-7.86.0/lib目录
CMakeLists.txt记录了要加载的文件目录、预定义项信息。
文件目录:
预定义项信息:
配置config文件:
有config-win32.h、config-mac.h、config-linux.h
config-win32.h在文件夹下,不需修改。
基于config-mac.h,构建config-linux.h
config-linux.h文件信息:
config-mac.h文件信息:
配置头文件:
#头文件
HEADERS += ./altsvc.h \
./amigaos.h \
./arpa_telnet.h \
./asyn.h \
./bufref.h \
./c-hyper.h \
./conncache.h \
./connect.h \
./content_encoding.h \
./cookie.h \
./curl_addrinfo.h \
./curl_base64.h \
./curl_ctype.h \
./curl_des.h \
./curl_endian.h \
./curl_fnmatch.h \
./curl_get_line.h \
./curl_gethostname.h \
./curl_gssapi.h \
./curl_hmac.h \
./curl_krb5.h \
./curl_ldap.h \
./curl_md4.h \
./curl_md5.h \
./curl_memory.h \
./curl_memrchr.h \
./curl_multibyte.h \
./curl_ntlm_core.h \
./curl_ntlm_wb.h \
./curl_path.h \
./curl_printf.h \
./curl_range.h \
./curl_rtmp.h \
./curl_sasl.h \
./curl_setup.h \
./curl_setup_once.h \
./curl_sha256.h \
./curl_sspi.h \
./curl_threads.h \
./curlx.h \
./dict.h \
./doh.h \
./dotdot.h \
./dynbuf.h \
./easyif.h \
./easyoptions.h \
./escape.h \
./file.h \
./fileinfo.h \
./fopen.h \
./formdata.h \
./ftp.h \
./ftplistparser.h \
./getinfo.h \
./gopher.h \
./h2h3.h \
./hash.h \
./headers.h \
./hostip.h \
./hsts.h \
./http2.h \
./http_aws_sigv4.h \
./http_chunks.h \
./http_digest.h \
./http.h \
./http_negotiate.h \
./http_ntlm.h \
./http_proxy.h \
./if2ip.h \
./imap.h \
./inet_ntop.h \
./inet_pton.h \
./llist.h \
./memdebug.h \
./mime.h \
./mqtt.h \
./multihandle.h \
./multiif.h \
./netrc.h \
./nonblock.h \
./noproxy.h \
./parsedate.h \
./pingpong.h \
./pop3.h \
./progress.h \
./psl.h \
./quic.h \
./rand.h \
./rename.h \
./rtsp.h \
./select.h \
./sendf.h \
./setopt.h \
./setup-vms.h \
./share.h \
./sigpipe.h \
./slist.h \
./smb.h \
./smtp.h \
./sockaddr.h \
./socketpair.h \
./socks.h \
./speedcheck.h \
./splay.h \
./strcase.h \
./strdup.h \
./strerror.h \
./strtok.h \
./strtoofft.h \
./system_win32.h \
./telnet.h \
./tftp.h \
./timediff.h \
./timeval.h \
./transfer.h \
./urlapi-int.h \
./urldata.h \
./url.h \
./version_win32.h \
./warnless.h \
./wildcard.h \
\
./vauth/digest.h \
./vauth/ntlm.h \
./vauth/vauth.h \
\
./vquic/msh3.h \
./vquic/ngtcp2.h \
./vquic/quiche.h \
./vquic/vquic.h \
\
./vssh\ssh.h \
\
./vtls/bearssl.h \
./vtls/gskit.h \
./vtls/gtls.h \
./vtls/hostcheck.h \
./vtls/keylog.h \
./vtls/mbedtls.h \
./vtls/mbedtls_threadlock.h \
./vtls/nssg.h \
./vtls/openssl.h \
./vtls/rustls.h \
./vtls/schannel.h \
./vtls/sectransp.h \
./vtls/vtls.h \
./vtls/wolfssl.h \
./vtls/x509asn1.h
win32 {
HEADERS += ./config-win32.h
}
linux* {
HEADERS += ./config-linux.h
}
macx {
HEADERS += ./config-mac.h
}
配置源文件:
#源文件
SOURCES += ./altsvc.c \
./amigaos.c \
./asyn-ares.c \
./asyn-thread.c \
./base64.c \
./bufref.c \
./c-hyper.c \
./conncache.c \
./connect.c \
./content_encoding.c \
./cookie.c \
./curl_addrinfo.c \
./curl_des.c \
./curl_endian.c \
./curl_fnmatch.c \
./curl_gethostname.c \
./curl_get_line.c \
./curl_gssapi.c \
./curl_memrchr.c \
./curl_multibyte.c \
./curl_ntlm_core.c \
./curl_ntlm_wb.c \
./curl_path.c \
./curl_range.c \
./curl_rtmp.c \
./curl_sasl.c \
./curl_sspi.c \
./curl_threads.c \
./dict.c \
./doh.c \
./dynbuf.c \
./easy.c \
./easygetopt.c \
./easyoptions.c \
./escape.c \
./file.c \
./fileinfo.c \
./fopen.c \
./formdata.c \
./ftp.c \
./ftplistparser.c \
./getenv.c \
./getinfo.c \
./gopher.c \
./h2h3.c \
./hash.c \
./headers.c \
./hmac.c \
./hostasyn.c \
./hostip4.c \
./hostip6.c \
./hostip.c \
./hostsyn.c \
./hsts.c \
./http2.c \
./http_aws_sigv4.c \
./http.c \
./http_chunks.c \
./http_digest.c \
./http_negotiate.c \
./http_ntlm.c \
./http_proxy.c \
./idn_win32.c \
./if2ip.c \
./imap.c \
./inet_ntop.c \
./inet_pton.c \
./krb5.c \
./ldap.c \
./llist.c \
./md4.c \
./md5.c \
./memdebug.c \
./mime.c \
./mprintf.c \
./mqtt.c \
./multi.c \
./netrc.c \
./nonblock.c \
./noproxy.c \
./openldap.c \
./parsedate.c \
./pingpong.c \
./pop3.c \
./progress.c \
./psl.c \
./rand.c \
./rename.c \
./rtsp.c \
./select.c \
./sendf.c \
./setopt.c \
./sha256.c \
./share.c \
./slist.c \
./smb.c \
./smtp.c \
./socketpair.c \
./socks.c \
./socks_gssapi.c \
./socks_sspi.c \
./speedcheck.c \
./splay.c \
./strcase.c \
./strdup.c \
./strerror.c \
./strtok.c \
./strtoofft.c \
./system_win32.c \
./telnet.c \
./tftp.c \
./timediff.c \
./timeval.c \
./transfer.c \
./urlapi.c \
./url.c \
./version.c \
./version_win32.c \
./warnless.c \
./wildcard.c \
\
./vauth/cleartext.c \
./vauth/cram.c \
./vauth/digest.c \
./vauth/digest_sspi.c \
./vauth/gsasl.c \
./vauth/krb5_gssapi.c \
./vauth/krb5_sspi.c \
./vauth/ntlm.c \
./vauth/ntlm_sspi.c \
./vauth/oauth2.c \
./vauth/spnego_gssapi.c \
./vauth/spnego_sspi.c \
./vauth/vauth.c \
\
./vquic/msh3.c \
./vquic/ngtcp2.c \
./vquic/quiche.c \
./vquic/vquic.c \
\
./vssh/libssh2.c \
./vssh/libssh.c \
./vssh/wolfssh.c \
\
./vtls/bearssl.c \
./vtls/gskit.c \
./vtls/gtls.c \
./vtls/hostcheck.c \
./vtls/keylog.c \
./vtls/mbedtls.c \
./vtls/mbedtls_threadlock.c \
./vtls/nss.c \
./vtls/openssl.c \
./vtls/rustls.c \
./vtls/schannel.c \
./vtls/schannel_verify.c \
./vtls/sectransp.c \
./vtls/vtls.c \
./vtls/wolfssl.c \
./vtls/x509asn1.c
预定义项信息:
DEFINES += BUILDING_LIBCURL USE_OPENSSL USE_LIBSSH2 USE_IPV6 HAVE_LIBSSH2_H HAVE_STRUCT_TIMEVAL
win32 {
DEFINES += _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE
}
linux* {
DEFINES += linux
}
macx {
DEFINES += macintosh __MRC__
}
依赖的库文件:
CONFIG(debug, debug|release){
LIBS += -lssh2d
}else{
LIBS += -lssh2
}
win32 {
LIBS += -LD:/Qt/Tools/OpenSSL/Win_x64/lib
LIBS += -llibcrypto -llibssl -lwldap32
LIBS += -lcrypt32 -luser32 -lws2_32
}
linux* {
LIBS += -lcrypto -lssl
}
macx {
LIBS += -L/usr/local/opt/openssl@3/lib
LIBS += -lcrypto -lssl
}
形成的004.curl-7.86.0.pro文件:
QT += core network
TEMPLATE = lib
CONFIG += c++17
DESTDIR = ../QGIS
CONFIG(debug, debug|release){
MOC_DIR = ../build-QGIS/curl/Debug/moc
RCC_DIR = ../build-QGIS/curl/Debug/rcc
UI_DIR = ../build-QGIS/curl/Debug/ui
OBJECTS_DIR = ../build-QGIS/curl/Debug/obj
}else{
MOC_DIR = ../build-QGIS/curl/Release/moc
RCC_DIR = ../build-QGIS/curl/Release/rcc
UI_DIR = ../build-QGIS/curl/Release/ui
OBJECTS_DIR = ../build-QGIS/curl/Release/obj
}
CONFIG(debug, debug|release){
TARGET = curld
}else{
TARGET = curl
}
#DEFINES -= UNICODE
DEFINES += BUILDING_LIBCURL USE_OPENSSL USE_LIBSSH2 USE_IPV6 HAVE_LIBSSH2_H HAVE_STRUCT_TIMEVAL
win32 {
DEFINES += _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE
}
linux* {
DEFINES += linux
}
macx {
DEFINES += macintosh __MRC__
}
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
#当前目录
INCLUDEPATH += ./ ./include ./vauth ./vquic ./vssh
#openssl路径
win32 {
INCLUDEPATH += D:/Qt/Tools/OpenSSL/Win_x64/include
INCLUDEPATH += D:/Qt/Tools/OpenSSL/Win_x64/include/openssl
}
linux* {
INCLUDEPATH += /opt/Qt/Tools/OpenSSL/src/include
INCLUDEPATH += /opt/Qt/Tools/OpenSSL/src/include/openssl
}
macx {
INCLUDEPATH += /usr/local/opt/openssl@3/include
INCLUDEPATH += /usr/local/opt/openssl@3/include/openssl
}
#SSH2路径
INCLUDEPATH += ../libssh2-1.10.0
#LIBS
LIBS += -L../QGIS
CONFIG(debug, debug|release){
LIBS += -lssh2d
}else{
LIBS += -lssh2
}
win32 {
LIBS += -LD:/Qt/Tools/OpenSSL/Win_x64/lib
LIBS += -llibcrypto -llibssl -lwldap32
LIBS += -lcrypt32 -luser32 -lws2_32
}
linux* {
LIBS += -lcrypto -lssl
}
macx {
LIBS += -L/usr/local/opt/openssl@3/lib
LIBS += -lcrypto -lssl
}
#头文件
HEADERS += ./altsvc.h \
./amigaos.h \
./arpa_telnet.h \
./asyn.h \
./bufref.h \
./c-hyper.h \
./conncache.h \
./connect.h \
./content_encoding.h \
./cookie.h \
./curl_addrinfo.h \
./curl_base64.h \
./curl_ctype.h \
./curl_des.h \
./curl_endian.h \
./curl_fnmatch.h \
./curl_get_line.h \
./curl_gethostname.h \
./curl_gssapi.h \
./curl_hmac.h \
./curl_krb5.h \
./curl_ldap.h \
./curl_md4.h \
./curl_md5.h \
./curl_memory.h \
./curl_memrchr.h \
./curl_multibyte.h \
./curl_ntlm_core.h \
./curl_ntlm_wb.h \
./curl_path.h \
./curl_printf.h \
./curl_range.h \
./curl_rtmp.h \
./curl_sasl.h \
./curl_setup.h \
./curl_setup_once.h \
./curl_sha256.h \
./curl_sspi.h \
./curl_threads.h \
./curlx.h \
./dict.h \
./doh.h \
./dotdot.h \
./dynbuf.h \
./easyif.h \
./easyoptions.h \
./escape.h \
./file.h \
./fileinfo.h \
./fopen.h \
./formdata.h \
./ftp.h \
./ftplistparser.h \
./getinfo.h \
./gopher.h \
./h2h3.h \
./hash.h \
./headers.h \
./hostip.h \
./hsts.h \
./http2.h \
./http_aws_sigv4.h \
./http_chunks.h \
./http_digest.h \
./http.h \
./http_negotiate.h \
./http_ntlm.h \
./http_proxy.h \
./if2ip.h \
./imap.h \
./inet_ntop.h \
./inet_pton.h \
./llist.h \
./memdebug.h \
./mime.h \
./mqtt.h \
./multihandle.h \
./multiif.h \
./netrc.h \
./nonblock.h \
./noproxy.h \
./parsedate.h \
./pingpong.h \
./pop3.h \
./progress.h \
./psl.h \
./quic.h \
./rand.h \
./rename.h \
./rtsp.h \
./select.h \
./sendf.h \
./setopt.h \
./setup-vms.h \
./share.h \
./sigpipe.h \
./slist.h \
./smb.h \
./smtp.h \
./sockaddr.h \
./socketpair.h \
./socks.h \
./speedcheck.h \
./splay.h \
./strcase.h \
./strdup.h \
./strerror.h \
./strtok.h \
./strtoofft.h \
./system_win32.h \
./telnet.h \
./tftp.h \
./timediff.h \
./timeval.h \
./transfer.h \
./urlapi-int.h \
./urldata.h \
./url.h \
./version_win32.h \
./warnless.h \
./wildcard.h \
\
./vauth/digest.h \
./vauth/ntlm.h \
./vauth/vauth.h \
\
./vquic/msh3.h \
./vquic/ngtcp2.h \
./vquic/quiche.h \
./vquic/vquic.h \
\
./vssh\ssh.h \
\
./vtls/bearssl.h \
./vtls/gskit.h \
./vtls/gtls.h \
./vtls/hostcheck.h \
./vtls/keylog.h \
./vtls/mbedtls.h \
./vtls/mbedtls_threadlock.h \
./vtls/nssg.h \
./vtls/openssl.h \
./vtls/rustls.h \
./vtls/schannel.h \
./vtls/sectransp.h \
./vtls/vtls.h \
./vtls/wolfssl.h \
./vtls/x509asn1.h
win32 {
HEADERS += ./config-win32.h
}
linux* {
HEADERS += ./config-linux.h
}
macx {
HEADERS += ./config-mac.h
}
#源文件
SOURCES += ./altsvc.c \
./amigaos.c \
./asyn-ares.c \
./asyn-thread.c \
./base64.c \
./bufref.c \
./c-hyper.c \
./conncache.c \
./connect.c \
./content_encoding.c \
./cookie.c \
./curl_addrinfo.c \
./curl_des.c \
./curl_endian.c \
./curl_fnmatch.c \
./curl_gethostname.c \
./curl_get_line.c \
./curl_gssapi.c \
./curl_memrchr.c \
./curl_multibyte.c \
./curl_ntlm_core.c \
./curl_ntlm_wb.c \
./curl_path.c \
./curl_range.c \
./curl_rtmp.c \
./curl_sasl.c \
./curl_sspi.c \
./curl_threads.c \
./dict.c \
./doh.c \
./dynbuf.c \
./easy.c \
./easygetopt.c \
./easyoptions.c \
./escape.c \
./file.c \
./fileinfo.c \
./fopen.c \
./formdata.c \
./ftp.c \
./ftplistparser.c \
./getenv.c \
./getinfo.c \
./gopher.c \
./h2h3.c \
./hash.c \
./headers.c \
./hmac.c \
./hostasyn.c \
./hostip4.c \
./hostip6.c \
./hostip.c \
./hostsyn.c \
./hsts.c \
./http2.c \
./http_aws_sigv4.c \
./http.c \
./http_chunks.c \
./http_digest.c \
./http_negotiate.c \
./http_ntlm.c \
./http_proxy.c \
./idn_win32.c \
./if2ip.c \
./imap.c \
./inet_ntop.c \
./inet_pton.c \
./krb5.c \
./ldap.c \
./llist.c \
./md4.c \
./md5.c \
./memdebug.c \
./mime.c \
./mprintf.c \
./mqtt.c \
./multi.c \
./netrc.c \
./nonblock.c \
./noproxy.c \
./openldap.c \
./parsedate.c \
./pingpong.c \
./pop3.c \
./progress.c \
./psl.c \
./rand.c \
./rename.c \
./rtsp.c \
./select.c \
./sendf.c \
./setopt.c \
./sha256.c \
./share.c \
./slist.c \
./smb.c \
./smtp.c \
./socketpair.c \
./socks.c \
./socks_gssapi.c \
./socks_sspi.c \
./speedcheck.c \
./splay.c \
./strcase.c \
./strdup.c \
./strerror.c \
./strtok.c \
./strtoofft.c \
./system_win32.c \
./telnet.c \
./tftp.c \
./timediff.c \
./timeval.c \
./transfer.c \
./urlapi.c \
./url.c \
./version.c \
./version_win32.c \
./warnless.c \
./wildcard.c \
\
./vauth/cleartext.c \
./vauth/cram.c \
./vauth/digest.c \
./vauth/digest_sspi.c \
./vauth/gsasl.c \
./vauth/krb5_gssapi.c \
./vauth/krb5_sspi.c \
./vauth/ntlm.c \
./vauth/ntlm_sspi.c \
./vauth/oauth2.c \
./vauth/spnego_gssapi.c \
./vauth/spnego_sspi.c \
./vauth/vauth.c \
\
./vquic/msh3.c \
./vquic/ngtcp2.c \
./vquic/quiche.c \
./vquic/vquic.c \
\
./vssh/libssh2.c \
./vssh/libssh.c \
./vssh/wolfssh.c \
\
./vtls/bearssl.c \
./vtls/gskit.c \
./vtls/gtls.c \
./vtls/hostcheck.c \
./vtls/keylog.c \
./vtls/mbedtls.c \
./vtls/mbedtls_threadlock.c \
./vtls/nss.c \
./vtls/openssl.c \
./vtls/rustls.c \
./vtls/schannel.c \
./vtls/schannel_verify.c \
./vtls/sectransp.c \
./vtls/vtls.c \
./vtls/wolfssl.c \
./vtls/x509asn1.c
# Default rules for deployment.
#unix {
# target.path = /usr/lib
#}
#!isEmpty(target.path): INSTALLS += target
用QtCreator程序,打开004.curl-7.86.0.pro文件。
在windows下编译,形成:
在linux下编译,形成:
在macos下编译,形成: