[SOLVED]Gett api with QtNetwork
-
@ QByteArray data;
QUrl params;
params.addQueryItem("email", email);
params.addQueryItem("password", password);
params.addQueryItem("apikey", key);
data = params.encodedQuery();
QNetworkAccessManager *manager = new QNetworkAccessManager();
QNetworkRequest request(QUrl("https://open.ge.tt/1/users/login"));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream");
QNetworkReply *reply = manager->post(request, data);
qDebug()<<reply->readAll();
@
I am trying to login gett using the above code but reply->readAll is always returning ''
Here is the link of "Gett API Docs":https://open.ge.tt/1/doc/rest -
the post() function is asynchronous, so when you reach the readAll() function nothing is read yet.
You shoud connect at least "finished()":http://qt-project.org/doc/qt-4.8/qnetworkaccessmanager.html#finished signal to your own defined slot function and there managed read bytes. See the "detailed description":http://qt-project.org/doc/qt-4.8/qnetworkaccessmanager.html#details.
Another thing about "post()":http://qt-project.org/doc/qt-4.8/qnetworkaccessmanager.html#post function:bq. data must be open for reading and must remain valid until the finished() signal is emitted for this reply.
as stated in the doc, your QByteArray data; should be valid till the request is finished, so define it globally in your class.