[SOLVED] QNetworkAccessManager HTTPS code 2 error QNetworkReply::RemoteHostClosedError
-
Hi everyone,
I'm trying to invoke a REST Web Service through POST, if I run the exact same code without SSL, I get a correct response, but if I try it with SSL, I just get a RemoteHostClosedError, I don't get any certificate errors or anything, I added the ignoreSslErrors() so it ignores any certificate issues in case it doesn't work, but I still get code 2.
I added a sslErrors signal just to check if I catch any SSL errors, but it never gets triggered, so I don't know what's going on. I know my HTTPS service works because I already use it on a C# and a java app and it works as expected.
Here's the code I use to call the service:
@
void MainWindow::doPost()
{
/*
Creates the network access manager, request and reply
*/
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkRequest request;
QNetworkReply *reply = NULL;/*
Gets the URL from the text field and sets it to the request
Sets the request headers for authentication and content type
use the QSslConfiguration for enabling HTTPS
*/
request.setSslConfiguration(QSslConfiguration::defaultConfiguration());
request.setUrl(QUrl(ui->url->text()));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");/*
Connects the transmission finished signal from the manager, to the
finished request slot from this class
/
connect(manager, SIGNAL(finished(QNetworkReply)), SLOT(requestFinished(QNetworkReply*)));/*
Trigger the POST request
*/
reply = manager->post(request, QString("{hola:'nulo'}").toAscii());
reply->ignoreSslErrors();/*
Connects the reply progress signal to the set progress slot from
this class to be able to track the download so we can display it
*/
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(setProgress(qint64,qint64)));
}/*
Updates the progressbar as the response is downloaded
*/
void MainWindow::setProgress(qint64 received, qint64 total)
{
if (total > 0 && received > 0)
ui->downloadProgress->setValue((int) total / received);
}/*
Assigns the response downloaded from the HTTP request
to the text area
*/
void MainWindow::requestFinished(QNetworkReply reply)
{
/
If there was an error in the reply, display the error string
in the text area
*/
if (reply->error() > 0)
ui->result->setHtml(reply->errorString());/*
Else, display the results in the text area
*/
else
ui->result->setPlainText(reply->readAll());ui->downloadProgress->setValue(0);
}
@Any feedback? thoughts?
Thanks!
-
On line 29 of the code, I changed the ignoreSslErrors() function with the signal/slot like this:
@
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors()));
@But still get the same error, and I even added my own custom slot to replace ignoreSslErrors to see if it triggers something:
@
/*
Triggers when it was a SSL error
*/
void MainWindow::requestSslError(QList<QSslError> sslErrorList)
{
QString result = "SSL Errors: ";
QSslError sslerror;foreach (sslerror, sslErrorList) {
result.append(sslerror.errorString()).append("\n");
}
ui->result->setHtml(result);
}
@I set a breakpoint in it, but it never enters the slot, so I guess there are no SSL errors, but then, why is it sending me the error code 2?
I uploaded the REST service in a server I have at home, if someone can help me test this thing, I would be thankful, the URL is:
"http://beta.paeon.mx/pushApi/alertResponse":http://beta.paeon.mx/pushApi/alertResponse
If you test it with http, it works, and if you test it with https you get an error code 2.
Thanks!
-
Ok, after googling the error a lot, I found a nokia Developer forum that someone had the same problem, and it seems that somehow openSSL doesn't correctly support TLS 1.0, and he switched his server to use SSLv3 instead.
"The nokia forums thread":http://www.developer.nokia.com/Community/Discussion/showthread.php?214549-sslErrors-not-called
I enabled SSLv3 in my server and voila! it works, the problem is that, even though SSLv3 is still secure, there has to be a way to support TLS 1.0, but I guess having it working with SSLv3 for the moment buys me time to see how to make it work with the latest and greatest in web encryption.
EDIT:
I'm a fool, TLSv1 doesn't come by default, so on line 15 of my first post, instead of using just QSslConfiguration::defaultConfiguration(), I replaced it with:@
QSslConfiguration config = QSslConfiguration::defaultConfiguration();
config.setProtocol(QSsl::TlsV1);
request.setSslConfiguration(config);
@Thanks all!