现在我知道有很多帖子都关注这样的问题,但是我经历了很多这样的事情,似乎没有一个能解决我的问题。我有一个标准问题,即无法在SSL加密地址上执行GET或POST请求。例如:https://google.com
据我所知,我已经做好了一切。这就是我所做的:
设置ssl证书:
QFile file("://cacert.pem");
file.open(QIODevice::ReadOnly);
const QByteArray bytes = file.readAll();
const QSslCertificate certificate(bytes);
QSslSocket::addDefaultCaCertificate(certificate);
设置ssl协议:
QSslConfiguration sslconfig;
sslconfig.setProtocol(QSsl::TlsV1_0);
将所有OpenSsl dll添加到我的可执行文件目录
然而,仍然无济于事。我的程序显示ssl错误,没有调用QNetworkReply::encrypted()
信号,QSslSocket::supportsSsl()
仍然返回false。
我非常感谢任何帮助,因为我现在知道该怎么做。
编辑:
在QNetworkReply的sslErrors(QList<QSslError>)
上添加了一个将调试它的插槽:(此时尚未调用。)
connect(reply, SIGNAL(sslErrors(QList)), this, SLOT(debugSslErrors(QList &)));
还添加了检查我的证书何时打开:(成功打开)
if (!certFile.open(QIODevice::ReadOnly))
{
qDebug() << "Couldn't Open Resource File.";
qDebug() << "Error: " << certFile.errorString();
return;
}
这是我的PRO文件:
#-------------------------------------------------
#
# Project created by QtCreator 2017-03-28T17:43:36
#
#-------------------------------------------------
QT += core gui network
CONFIG += c+=11
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Gallery
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
mainwindow.cpp \
base.cpp \
post.cpp \
responsepost.cpp \
md5data.cpp \
tagdata.cpp \
postcreationdialog.cpp \
postgetdialog.cpp \
sslcipher.cpp
HEADERS += mainwindow.h \
base.h \
post.h \
sides.h \
responsepost.h \
md5data.h \
tagdata.h \
postcreationdialog.h \
postgetdialog.h \
sslcipher.h
FORMS += mainwindow.ui \
postcreationdialog.ui \
postgetdialog.ui
RESOURCES += \
files.qrc
LIBS += ../Libraries/OpenSSL-Win32/lib/libcrypto32MT.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/libcrypto32MTd.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/libeay32.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/libssl.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/libssl32MD.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/libssl32MDd.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/libssl32MT.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/libssl32MTd.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/openssl.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/ossltest.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/padlock.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/ssleay32.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/capi.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/dasync.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/Gdi32.Lib
LIBS += ../Libraries/OpenSSL-Win32/lib/GdiPlus.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/libcrypto.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/libcrypto32MD.lib
LIBS += ../Libraries/OpenSSL-Win32/lib/libcrypto32MDd.lib
INCLUDEPATH += $$PWD/../Libraries/OpenSSL-Win32/include
DEPENDPATH += $$PWD/../Libraries/OpenSSL-Win32/include