下载最新版的curl源码,这里下载的是7.64.1版本的。编译出的libcurl库支持https协议
网址:https://curl.haxx.se/download.html
2013平台编译:
开始菜单进入,查找Microsoft Visual Studio 2013->Visual Studio Tools打开Visual Studio 命令提示(2013)
命令提示窗口
C:\Program Files (x86)\Microsoft Visual Studio 12.0>
C:\Program Files (x86)\Microsoft Visual Studio 12.0>e:
E:\>cd E:\QtCurl\curl-7.64.1
E:\QtCurl\curl-7.64.1>
静态库编译方法:
======================================================
进入以下目录:
E:\QtCurl\curl-7.64.1>cd winbuild
E:\QtCurl\curl-7.64.1\winbuild>
脚本编译静态库 编译器2013
build_static_openssl.dat
文件内容如下:
@REM @echo off
@IF [%1]==[debug] (
@echo 正在使用debug模式编译libcurl~~~
@nmake /f Makefile.vc WITH_DEVEL=../../deps mode=static VC=12 ENABLE_IDN=no RTLIBCFG=dll DEBUG=yes MACHINE=x86
) ELSE (
@echo 正在使用release模式编译libcurl~~~
@nmake /f Makefile.vc WITH_DEVEL=../../deps mode=static VC=12 ENABLE_IDN=no RTLIBCFG=dll DEBUG=no MACHINE=x86
)
@REM @echo on
执行命令
E:\QtCurl\curl-7.64.1\winbuild>build_static_openssl.bat
编译过程........
E:\QtCurl\curl-7.64.1\winbuild>
查看是否支持https协议
E:\QtCurl\curl-7.64.1\winbuild>cd E:\QtCurl\curl-7.64.1\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\bin
E:\QtCurl\curl-7.64.1\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\bin>curl -V
curl 7.64.1 (i386-pc-win32) libcurl/7.64.1 Schannel
Release-Date: 2019-03-27
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s
rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Kerberos Largefile NTLM SPNEGO SSL SSPI
E:\QtCurl\curl-7.64.1\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\bin>
编译成功,支持https
======================================================================================
动态库编译方法:
=======================================================
进入以下目录:
E:\QtCurl\curl-7.64.1\winbuild>
脚本编译静态库 编译器2013
build_dll_openssl.dat
文件内容如下:
@REM @echo off
@IF [%1]==[debug] (
@echo 正在使用debug模式编译libcurl~~~
@nmake /f Makefile.vc WITH_DEVEL=../../deps mode=dll VC=12 ENABLE_IDN=no RTLIBCFG=dll DEBUG=yes MACHINE=x86
) ELSE (
@echo 正在使用release模式编译libcurl~~~
@nmake /f Makefile.vc WITH_DEVEL=../../deps mode=dll VC=12 ENABLE_IDN=no RTLIBCFG=dll DEBUG=no MACHINE=x86
)
@REM @echo on
执行脚本:
E:\QtCurl\curl-7.64.1\winbuild>build_dll_openssl.bat
编译过程........
E:\QtCurl\curl-7.64.1\winbuild>
查看是否支持https协议:
E:\QtCurl\curl-7.64.1\winbuild>cd E:\QtCurl\curl-7.64.1\builds\libcurl-vc10-x86-release-dll-ipv6-sspi-winssl\bin
E:\QtCurl\curl-7.64.1\builds\libcurl-vc10-x86-release-dll-ipv6-sspi-winssl\bin>curl -V
curl 7.64.1 (i386-pc-win32) libcurl/7.64.1 Schannel
Release-Date: 2019-03-27
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s
rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Kerberos Largefile NTLM SPNEGO SSL SSPI
E:\QtCurl\curl-7.64.1\builds\libcurl-vc10-x86-release-dll-ipv6-sspi-winssl\bin>
libcurl.dll也在这个目录下
由于2013平台编译的获取url的文件大小不正确,
long long qtCurl2013Dome::GetDownloadFileSize(QString &url)
{
double fileLength = 0;
CURL *curlHandle = curl_easy_init();
std::string strUrl = url.toStdString();
int copyLength = strUrl.length();
char charUrl[512] = {'\0'};
memcpy(charUrl, strUrl.c_str(), copyLength);
//const char charUrl[] = "https://qc2.androidfilehost.com/dl/qStvpxTEp4F_2ABz7uld0g/1555562519/11410963190603915633/COMBINATION_OXA_FA44_A500FXXU1APD1.zip";
qDebug() << "charUrl==========================" << charUrl << copyLength;
curl_easy_setopt(curlHandle, CURLOPT_URL, charUrl);
curl_easy_setopt(curlHandle, CURLOPT_HEADER, 1);//只需要header头
curl_easy_setopt(curlHandle, CURLOPT_NOBODY, 1);//不需要body
qDebug() << "curl_easy_perform(curlHandle)==========================" << curl_easy_perform(curlHandle);
//返回CURLE_WRITE_ERROR 23
if (curl_easy_perform(curlHandle) == CURLE_OK)
{
curl_easy_getinfo(curlHandle, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &fileLength);
}
else
{
fileLength = -1;
}
return fileLength;
}
curl_easy_perform(curlHandle)这里返回23,而用2010平台编译的是正常的,源码是同一份,
2010平台编译脚本如下:
2010build_dll_openssl.dat
文件内容如下:
@REM @echo off
@IF [%1]==[debug] (
@echo 正在使用debug模式编译libcurl~~~
@nmake /f Makefile.vc WITH_DEVEL=../../deps mode=dll VC=10 ENABLE_IDN=no RTLIBCFG=dll DEBUG=yes MACHINE=x86
) ELSE (
@echo 正在使用release模式编译libcurl~~~
@nmake /f Makefile.vc WITH_DEVEL=../../deps mode=dll VC=10 ENABLE_IDN=no RTLIBCFG=dll DEBUG=no MACHINE=x86
)
@REM @echo on