我的目标是使用QNetworkRequest
QNetworkAccessManager
通过SSL连接从网页获取源代码(或图像)。
OpenSSL 1.1.0不适用于Qt 5.8!在Edit 2中查看安装解决方案!
首先尝试:获取ssleay32.lib和libeay32.lib并将它们复制到debug和release文件夹中。不工作。
第二次尝试:(已删除,因为它是废话) 但它不再起作用了。
代码(适用于普通的http):
QUrl url = QUrl(name);
data.clear();
QNetworkRequest *request = new QNetworkRequest(url);
request->setRawHeader("User-Agent", userAgent);
QSslConfiguration sslConfiguration(QSslConfiguration::defaultConfiguration());
request->setSslConfiguration(sslConfiguration);
reply = webCtrl->get(*request);
connect(webCtrl, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
connect(reply, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
connect(reply, SIGNAL(finished()), this, SLOT(onReplyFinished()));
错误讯息:
qt.network.ssl: QSslSocket: cannot call unresolved function d2i_DHparams
qt.network.ssl: QSslSocket: cannot call unresolved function DH_free
qt.network.ssl: QSslSocket: cannot call unresolved function d2i_DHparams
qt.network.ssl: QSslSocket: cannot call unresolved function DH_free
qt.network.ssl: QSslSocket: cannot call unresolved function d2i_DHparams
qt.network.ssl: QSslSocket: cannot call unresolved function DH_free
qt.network.ssl: QSslSocket: cannot call unresolved function SSLv23_client_method
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_CTX_new
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_library_init
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
Error creating SSL context ()
编辑1:
我发现this Artikel和OpenSSL 1.1.0将使用Qt 5.10但不是Qt 5.8我正在使用的。
在this Artikel中,我找到了QSslSocket::sslLibraryBuildVersionString()
命令,我需要OpenSSL版本:OpenSSL 1.0.2h 3 May 2016
。
我将稍后检查其他OpenSSL版本并编辑此帖子是否有效。
编辑2:
下载OpenSSL 1.0.2h 3 May 2016
并安装7zip和Perl。解压缩openSSL文件夹并按INSTALL.W64
进行操作。转到bin
文件夹,将libeay32-xxx.dll
和ssleay32-xxx.dll
复制到应用程序文件夹,然后将文件重命名为libeay32.dll
和ssleay32.dll
。谢谢@ [Max Go]。
现在SSL连接最终有效,但是当我关闭应用程序并在运行时使用Web连接时,我收到一条错误消息。
onlineTest.exe中0x000000007772D1CB(ntdll.dll)的异常: 0xC0000005:访问冲突读取位置0x0000000000000074。
VS2015调试窗口" mem.c"第443行:
free_debug_func 0x0000000000000000 void(*)(void *, int)
free_func 0x000007fee778b1ba {libeay32.dll!free} void(*)(void *)
str 0x0000000002500cf0 void *
编辑3: 我忘了编译-d debug .dll' s。只需将编译器模式更改为Debug,生成Debug .dll,如果需要,在不使用-d的情况下重命名,然后将调试.dll复制到调试文件夹,将普通.dll复制到.dll中。发布文件夹。
答案 0 :(得分:4)
这是我用来从Visual Studio提示符自动构建OpenSSL的脚本。它将构建32位或64位库,具体取决于启用的编译器。
先决条件(必须在PATH中):
:: Configurable Options
:: If you have jom available, set it to jom - it speeds up the build.
@set JOM=nmake
:: Choose a static or dynamic build
@set LIBTYPE=dynamic
:: OpenSSL version in the 1.0.2 series
@set SRC=openssl-1.0.2k
@if "%VSCMD_ARG_TGT_ARCH%"=="x86" (
@set BITS=32
@set DST=OpenSSL-Win32
@set CONFIG=VC-WIN32
@set SETUP=ms\do_nasm
) else if "%VSCMD_ARG_TGT_ARCH%"=="x64" (
@set BITS=64
@set DST=OpenSSL-Win64
@set CONFIG=VC-WIN64A
@set SETUP=ms\do_win64a
) else goto no_vscmd
@if "%LIBTYPE%"=="static" (
@set LIBTYPE=nt
) else if "%LIBTYPE%"=="dynamic" (
@set LIBTYPE=ntdll
) else goto no_libtype
@echo Building %SRC% for %BITS% bits.
@echo - Downloading
@perl ^
-e "use LWP::Simple;" ^
-e "mirror('https://www.openssl.org/source/%SRC%.tar.gz', '%SRC%.tar.gz');"
@echo - Decompressing
@if not exist %SRC%.tar.gz goto no_archive
@rmdir /S /Q %SRC% %DST% 2>NUL
@7z x -bsp2 -y %SRC%.tar.gz >NUL && ^
7z x -bsp2 -y %SRC%.tar >NUL && ^
del %SRC%.tar
@if errorlevel 1 goto unpack_failed
@if not exist %SRC% goto no_source
@echo - Building
@pushd %SRC%
@perl Configure %CONFIG% --prefix=%~dp0..\%DST% && ^
call %SETUP% && ^
nmake -f ms\%LIBTYPE%.mak init && ^
%JOM% -f ms\%LIBTYPE%.mak "CC=cl /FS" && ^
%JOM% -f ms\%LIBTYPE%.mak test && ^
nmake -f ms\%LIBTYPE%.mak install || goto build_failed
@popd
@rmdir /S /Q %SRC%
@echo Build has succeeded.
@goto :eof
:no_libtype
@echo Error: LIBTYPE must be either "static" or "dynamic">&2
@exit /b 1
:no_archive
@echo Error: can't find %SRC%.tar.gz - the download has failed :(>&2
@exit /b 1
:unpack_failed
@echo Error: unpacking has failed.>&2
@exit /b %errorlevel%
:no_source
@echo Error: can't find %SRC%\>&2
@exit /b 1
:build_failed
@echo The build had failed.>&2
@popd
@exit /b 2
:no_vscmd
@echo Use vcvarsall x86 or vcvarsall x64 to set up the Visual Studio>&2
@echo build environment first.>&2
@exit /b 100