I have a secured URL working with an x509 certificate and I am supposed to receive a JSON as an answer. My certificate is in pfx format (ca certificate, local certificate, key). I added it on the computer and when launching a request on google chrome and internet explorer with the secured URL I have indeed the JSON as an answer.
My problem is when I try to do the same inside my Qt application I do not have any answer from the same URL. My code :
QSslConfiguration config = QSslConfiguration::defaultConfiguration();
config.setProtocol(QSsl::TlsV1_2);
_manager = std::make_unique<QNetworkAccessManager>();
auto line = "myurl";
qInfo() << line;
QNetworkRequest request((QUrl::fromUserInput(line)));
request.setSslConfiguration(config);
QEventLoop loop;
connect(_manager.get(), &QNetworkAccessManager::finished, &loop,
&QEventLoop::quit,
Qt::DirectConnection);
connect(_manager.get(), &QNetworkAccessManager::sslErrors, this,
&CheckConfController::sslErrors);
_loginReply = std::unique_ptr<QNetworkReply>(_manager->get(request));
connect(_loginReply.get(), &QNetworkReply::readyRead,
this, &CheckConfController::replyFinished);
connect(_loginReply.get(), &QNetworkReply::finished,
this, &CheckConfController::_loginReceive);
loop.exec();
The login receive method :
void CheckConfController::_loginReceive(){
qInfo() << "status code : " << _loginReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
qInfo() << "error : " << _loginReply->error();
qInfo() << "error string : " << _loginReply->errorString();
QByteArray b = _loginReply->readAll();
qInfo() << "byte : " << b;
}
The SSL error method :
void CheckConfController::sslErrors(QNetworkReply* reply, const QList<QSslError> &errors)
{
QByteArray b = reply->readAll();
qInfo() << "reply : " << b;
for(auto element : errors){
qInfo() << "ssl error : " << element;
}
}
This is mu Outpput :
status code: QVariant(Invalid)
error: QNetworkReply::RemoteHostClosedError
err string: "Connection Closed"
byte : ""
SSL error is never called.
I switched my URL line to https://www.google.com and it works fine. I also tried with other urls and i receive my json correctly.
This is my configuration:
Qt version: 5.12.11
compiler: MSVC 2017 64 bits
Computer running the application: Windows 7
Any help would be appreciated. Thank you.