QNetworkAccessManager fails while curl work
-
Hi,
I am experimenting with REST server and client in Qt.
I develop on Linux and Qt 6.5 and run both client and server on local host.
As server software I have the simple http server example with fixated http port to 8080 and https port to 4430. The problem was there with the original code.
I have also added a self signed certificate.On the client side I have the following code from the HTTP Client example:
QUrl url("https://<fqdn to localhost>"); QNetworkAccessManager* nam = new QNetworkAccessManager(this); QNetworkRequest request(url); url.setPort(4430); connect(nam, &QNetworkAccessManager::finished, this, &MainWindow::finished); connect(nam, &QNetworkAccessManager::sslErrors, this, &MainWindow::sslErrors); QSslConfiguration sslConf = request.sslConfiguration(); QList<QSslCertificate> caCerts = QSslCertificate::fromPath(QStringLiteral(":/assets/rootCA.crt")); sslConf.addCaCertificates(caCerts); request.setSslConfiguration(sslConf); nam->get(request);
I have added my own CA root certificate to accept the server certificate.
When I run the client, I get QNetworkReply::ConnectionRefusedError in MainWindow::finished.
Using curl with the supplied CA root certifiacte and the sam URL and port works like a charm.
And I am clueless.
Any suggestions what I have made wrong or how I can find the problem?
-
Hi and welcome to devnet,
Did you get something from the sslErrors slot ?
Did you get any information server side about that connection being tried ?
Did you also check whether the encrypted signal was emitted ?
While it should work, you should also check that the call toaddCaCertificates
was successful. -
Thanks for the tips and @hskoglund , the crul --lib option is a really cool trick I will never forget.
And @SGaist, thanks for the checklist, I'll keep it in mind. 30 years of C++, quite some time with C-level sockets and newbie on modern networking in Qt I need all help I can get.
I found the problem and it is a typo.
I rearranged the code and the URL-port is set after I have used the object to initiate the network request. I shifted the lines and things are working as supposed.
I figure I just needed some time away from the code to actually READ the code ;)
-