Hello, I am new to QT5 and I am having some trouble with QNetworkAccessManager. I need to create a login form that uses HTTPS but when I make a request I get
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
To copy to clipboard, switch view to plain text mode
Here is my code inside mainwindow.cpp:
QUrl loginUrl
= QUrl("https://172.30.254.30/api/login");
QUrlQuery postData;
postData.addQueryItem("email",email);
postData.addQueryItem("password",password);
qInfo() << email << " " << password;
QNetworkAccessManager *netManager = new QNetworkAccessManager(this);
connect(netManager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(sslFix(QNetworkReply*)));
connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestFinished(QNetworkReply*)));
QNetworkRequest request(loginUrl);
request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
netManager
->post
(request, postData.
toString(QUrl::FullyEncoded).
toUtf8());
QUrl loginUrl = QUrl("https://172.30.254.30/api/login");
QUrlQuery postData;
postData.addQueryItem("email",email);
postData.addQueryItem("password",password);
qInfo() << email << " " << password;
QNetworkAccessManager *netManager = new QNetworkAccessManager(this);
connect(netManager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(sslFix(QNetworkReply*)));
connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestFinished(QNetworkReply*)));
QNetworkRequest request(loginUrl);
request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
netManager->post(request, postData.toString(QUrl::FullyEncoded).toUtf8());
To copy to clipboard, switch view to plain text mode
void MainWindow::requestFinished(QNetworkReply *response) {
qInfo() << "Raw: " << res;
}
void MainWindow::requestFinished(QNetworkReply *response) {
QByteArray res = response->readAll();
qInfo() << "Raw: " << res;
}
To copy to clipboard, switch view to plain text mode
void MainWindow::sslFix(QNetworkReply *request){
request->ignoreSslErrors();
}
void MainWindow::sslFix(QNetworkReply *request){
request->ignoreSslErrors();
}
To copy to clipboard, switch view to plain text mode
Any help would be great!
Thanks,
James
Bookmarks