PDA

View Full Version : Example for QNetworkAccessManager with SSL



KeineAhnung
11th February 2016, 22:04
Hi,

I would like to upgrade my network request to SSL but was not able to find an example on the web how to do this properly. Here is the code I currently have:


manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(url)); // url = http://xyz...


I changed it to this:


QSslConfiguration sslConfiguration(QSslConfiguration::defaultConfigu ration());
sslConfiguration.setProtocol(QSsl::TlsV1_2);

manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(url)); // url = https://xyz...


The second part is still working, which is really surprising since I use a self-signed ssl certificate. So I am guessing I am doing something wrong here. Can someone help?

Thanks!

code_err
12th February 2016, 13:52
I don't really know what You've done but when I used SSL I did it this way (and it worked):


QNetworkRequest request();
request.setSslConfiguration(QSslConfiguration::def aultConfiguration());

and in application directory I put these files (these are OpenSSL library files):
libeay32.dll
ssleay32.dll

from: http://www.npcglib.org/~stathis/blog/precompiled-openssl/

btw. I think that You just did nothing in this code:

QSslConfiguration sslConfiguration(QSslConfiguration::defaultConfigu ration());
sslConfiguration.setProtocol(QSsl::TlsV1_2);
because You created object that is not used anywhere.