Created
July 23, 2012 13:12
-
-
Save rla/3163550 to your computer and use it in GitHub Desktop.
Sending JSON POST request with Qt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void SyncService::sync() | |
{ | |
QUrl url(SYNC_URL); | |
QNetworkRequest request(url); | |
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | |
QNetworkAccessManager *manager = new QNetworkAccessManager(this); | |
connect(manager, SIGNAL(finished(QNetworkReply*)), | |
this, SLOT(syncRequestFinished(QNetworkReply*))); | |
QByteArray data = QtJson::Json::serialize(collectSyncData()); | |
// FIXME for debug | |
qDebug() << "Sync" << QString::fromUtf8(data.data(), data.size()); | |
manager->post(request, data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot! I am pretty new to Qt and haven't learned the API yet.