QtNetwork Empty response
-
I have a program that load dll, that contains executes code for http request, and code in it. On my Windows it works well - all ok, replies are correct and etc. But when I decided to test program on pure Windows on VMWare without libs (to understand did I include all nedeed depencies in installer) I got really strange bug: reply on new OS is always empty. Furthermore, seems that it never reaches server. It shows in erorr status "SSL Handshake failed". I tried to install on new OS Open SSL (I found in Google that can help), MS VC++ all versions, Windows SDK and more... But nothing helps. On my old windows still all ok... Please, help me to understand what's going on. Here come code and logs, that I got on new OS:
@#include "portalbiocad.h"#define EXT(description, code) qDebug() << description; return code;
const char *lastError = "no error";
const char *URL_TOKEN = "https://portal.biocad.ru/link/auth.php";
const char *URL_AUTH = "https://portal.biocad.ru/link/auth.php?token=%1";//+
RESULT Run(const char *k, void *p)
{
qDebug() << FUNCTION ;// Check args if ((void*)k == (void*)0) { lastError = "(void*)k == (void*)0) is true"; EXT(lastError, RESULT_WRONGARGS); } if ((void*)p != (void*)0) { lastError = "((void*)p != (void*)0) is true"; EXT(lastError, RESULT_WRONGARGS); } QString key(k); if (key.isEmpty()) { lastError = "Key is empty"; EXT(lastError, RESULT_WRONGKEY); } // Start working qDebug() << "Before QString reply = PostRequest(key);"; QString reply = PostRequest(key); qDebug() << "After QString reply = PostRequest(key);"; if (reply.isEmpty()) { lastError = "Reply is empty"; EXT(lastError, RESULT_UNKNOWN_ERROR); } else if (reply == "GoodTry!") { lastError = "Reply is \"GoodTry\""; EXT(lastError, RESULT_WRONGKEY); } QString token_url(URL_AUTH); token_url = token_url.arg(reply); bool success = QDesktopServices::openUrl(token_url); if (success) { lastError = "No error, success"; EXT(lastError, RESULT_SUCCESS); } else { lastError = "OpenUrl is false, failure"; EXT(lastError, RESULT_FAILURE); } lastError = "Amazing error, nobody knows what there have been"; EXT(lastError, RESULT_UNKNOWN_ERROR);
}
//+
const char *GetPluginName()
{
return "Portal Biocad";
}//+
const char *GetLastError()
{
return lastError;
}//+-
bool IsAvailable(const char key)
{
(void) key;/* if (key.empty()) { return 0; } QString reply = PostRequest(""); if (reply.isEmpty()) { return 0; } else { return 1; }//*/ return true;
}
//+
QString PostRequest(const QString &key)
{
// setting POST request params
QUrl params;
params.addQueryItem("key", key);
// creating request
QNetworkRequest request;
request.setUrl(QString(URL_TOKEN));
request.setHeader(QNetworkRequest::ContentTypeHeader,
QVariant("application/x-www-form-urlencoded"));// executing request QNetworkAccessManager manager; QEventLoop wait_reply; QObject::connect(&manager, SIGNAL(finished(QNetworkReply*)), &wait_reply, SLOT(quit())); QNetworkReply *answer = manager.post(request, params.encodedQuery()); qDebug() << "Before wait_reply.exec();"; wait_reply.exec(); if (answer) { if (answer->error() == QNetworkReply::NoError) { const int available = answer->bytesAvailable(); if (available > 0) { return QString(answer->readAll()); } } else { qDebug() << QString("Error: %1 status: %2").arg( answer->errorString(), answer->attribute( QNetworkRequest:: HttpStatusCodeAttribute).toString()); } qDebug() << "code: " << answer->attribute( QNetworkRequest:: HttpStatusCodeAttribute).toString() << " response: " << answer->readAll(); answer->deleteLater(); } qDebug() << "After wait_reply.exec();"; return "";
}@
Logs:
@Run
Before QString reply = PostRequest(key);
Before wait_reply.exec();
"Error: SSL handshake failed status: "
code: "" response: ""
After wait_reply.exec();
After QString reply = PostRequest(key);
Reply is empty@Windows 7, Qt 4.8.6, Open SSL v1.0.1j Light, all x64
-
Hi,
Most likely your application can't find the OpenSSL dlls. If you are running Qt Creator, go to the run part of the Project panel and update the PATH environment variable there to also include the path where the OpenSSL libraries can be found.
If it works out of the box in your old windows, it's likely that some software installed it system wide or added itself to the PATH and also contain these libs.
-
[quote author="SGaist" date="1415654799"]Hi,
Most likely your application can't find the OpenSSL dlls. If you are running Qt Creator, go to the run part of the Project panel and update the PATH environment variable there to also include the path where the OpenSSL libraries can be found.
If it works out of the box in your old windows, it's likely that some software installed it system wide or added itself to the PATH and also contain these libs.[/quote]
Hi. Yep, I tried to add all libs as I know app need in system32 and app dir, where system can find it, but that's not help. Now it works on new system with
@QSslConfiguration::setPeerVerifyMode(QSslSocket::VerifyNone)@
that I set for QNetworkRequest, but seems that is not the best way. -
Don't add libs in system32 or any other path like that, you don't know which application on your system is using OpenSSL and you might be breaking them.