Why the post method doesn't send the json to API Rest in QT5?
-
@p3c0 I left it running for a while, but the replyFinished method seems as if it were not called
@trip
since it looks like you are posting to a https url, do you have OpenSSL properly configured? -
@raven-worx
No, I have not configured. Do you think is the problem? -
@raven-worx
No, I have not configured. Do you think is the problem?@trip
yes ;)
But you should get some SSL errors printed in the debugger console (during initialization)On what system are you developing on?
-
@raven-worx
Okay. What is the right flow to follow to configure OpenSSL correctly?
In fact I like errorsqt.network.ssl: QSslSocket: can not resolve SSLv2_client_method qt.network.ssl: QSslSocket: can not resolve SSLv2_server_method
I'm using Ubuntu 16 and Qt Creator 4
-
@raven-worx
Okay. What is the right flow to follow to configure OpenSSL correctly?
In fact I like errorsqt.network.ssl: QSslSocket: can not resolve SSLv2_client_method qt.network.ssl: QSslSocket: can not resolve SSLv2_server_method
I'm using Ubuntu 16 and Qt Creator 4
@trip
yea, about those errors i was talking.
Since you are on Ubuntu simply install the OpenSSL binaries (via the system package manager) and it should work. -
@raven-worx
I had already installed the package. I run the program but I always make the same error. -
@raven-worx
Should I use the connectToHostEncrypted method of the QNetworkAccessManager class? -
@raven-worx
Should I use the connectToHostEncrypted method of the QNetworkAccessManager class?@trip For using https enough call message get/put/post with https urls, for example
QNetworkRequest req; req.setUrl(QUrl("https://cloud-api.yandex.net/v1/disk/"));
and this is working in my program.
-
@raven-worx
Should I use the connectToHostEncrypted method of the QNetworkAccessManager class?it has to be in a path where your application can find it.
no not needed. Should all happen internally. Just make sure your application can find the OpenSSL binaries.
-
it has to be in a path where your application can find it.
no not needed. Should all happen internally. Just make sure your application can find the OpenSSL binaries.
@raven-worx for example, we can put together with the executable file.
-
@raven-worx
I tried to do another project where there is just main.cpp and where do#include <QCoreApplication> #include <QNetworkAccessManager> #include <QNetworkReply> #include <QNetworkRequest> #include <QDebug> #include <QObject> #include <QByteArray> #include <QUrl> void replyFinished(QNetworkReply *reply) { reply->deleteLater(); qDebug() << "reply delete!"; qDebug() << "https post_request done!"; } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QNetworkAccessManager *manager = new QNetworkAccessManager(); QNetworkRequest request(QUrl ("https://cryptic-reaches-94837.herokuapp.com/data/")); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QObject::connect(manager, &QNetworkAccessManager::finished, replyFinished); quint8 speed = 0x12; quint8 acceleration = 0x5b; QString json = QString("{\"speed\":\"%1\",\"acceleration\":\"%2\"}").arg(speed).arg(acceleration); manager->post(request, json.toUtf8()); return a.exec(); }
and it's work!!!
but how come if add this piece of code to my project, why does not work to me? -
@raven-worx
I tried to do another project where there is just main.cpp and where do#include <QCoreApplication> #include <QNetworkAccessManager> #include <QNetworkReply> #include <QNetworkRequest> #include <QDebug> #include <QObject> #include <QByteArray> #include <QUrl> void replyFinished(QNetworkReply *reply) { reply->deleteLater(); qDebug() << "reply delete!"; qDebug() << "https post_request done!"; } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QNetworkAccessManager *manager = new QNetworkAccessManager(); QNetworkRequest request(QUrl ("https://cryptic-reaches-94837.herokuapp.com/data/")); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QObject::connect(manager, &QNetworkAccessManager::finished, replyFinished); quint8 speed = 0x12; quint8 acceleration = 0x5b; QString json = QString("{\"speed\":\"%1\",\"acceleration\":\"%2\"}").arg(speed).arg(acceleration); manager->post(request, json.toUtf8()); return a.exec(); }
and it's work!!!
but how come if add this piece of code to my project, why does not work to me?@trip
but thats a different URL now?!
Check the returned response error again. -
@raven-worx
not only here I left explicit -
@raven-worx
I think the problem of my code is that networking events are not processed by QCoreApplication :: exec () and then, because the execution is always nested in the cycles and never returns to the main unless there is an error , I do not run networking events. How can I solve this problem?