Qt How can I send an https request to the server?

I tried to send a receive request using https url. The answer is empty, but there is no error message. I download OpenSSL and copied the libeay32.dll and ssleay32.dll files to the folder C: \ Qt \ Qt5.1.1 \ Tools \ QtCreator \ bin.

code:

QNetworkAccessManager *manager = new QNetworkAccessManager(); QNetworkRequest request; QNetworkReply *reply = NULL; QSslConfiguration config = QSslConfiguration::defaultConfiguration(); config.setProtocol(QSsl::TlsV1_2); request.setSslConfiguration(config); request.setUrl(QUrl(url)); request.setHeader(QNetworkRequest::ServerHeader, "application/json"); reply = manager->get(request); qDebug() << reply->readAll(); 
+6
source share
1 answer

As Frank wrote in his comet, the get function is asynchronous, so when you try to read the response, the HTTP request is not yet complete.

To solve this problem, you need to process the finished signal:

 connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); 

and read the results in the handler:

 void NetworkHandler::replyFinished(QNetworkReply *reply) { qDebug() << reply->readAll(); } 
+3
source

All Articles