Code:
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QString resultString
="{\"user\": {\"login\": \""+login
+"\",\"firstname\": \""+firstname
+"\",\"lastname\": \""+lastname
+"\",\"mail\": \""+email
+"\", \"password\": \""+password
+"\"}}";
qDebug() << "string to post to redmine : " << resultString;
QByteArray dataByteArray
(resultString.
toLatin1());
QUrl url
("http://redmine-user.rhcloud.com/users.json");
QNetworkRequest request(url);
request.setRawHeader("User-Agent", "ApplicationNameV01");
request.setRawHeader("Content-Type", "application/json");
request.setRawHeader("Content-Length", postDataSize);
if (manager)
{
bool result;
QNetworkReply *reply = manager->post(request, dataByteArray);
/* The finished() signal is triggered once an HTTP request is complete, by connect method we are connecting finished signal with the slot method onRequestFinished(user defined method). If it returns true it means connection is successful else not. You can process the response of the call in this user defined method */
result = connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onRequestFinished(QNetworkReply*)));
qDebug() << "Connection is success : ? : " << result;
if (reply)
{
qDebug() << "Reply from server is " << reply;
}
}
Quote:
Console out :
string to post to redmine : "{\"user\": {\"login\": \"userid\",\"firstname\": \"userfname\",\"lastname\": \"userlname\",\"mail\": \"user@gmail.com\", \"password\": \"newuser123\"}}"
Connection is success : ? : true
Reply from server is QNetworkReplyHttpImpl(0x9249ef0)
"{\"user\":{\"id\":36,\"login\":\"userid\",\"first name\":\"userfname\",\"lastname\":\"userlname\",\" mail\":\"user@gmail.com\",\"created_on\":\"2016-05-23T15:06:56Z\",\"api_key\":\"3a628190f278342068a2b 07f37c2df8b85592a51\",\"status\":1}}"
From doc :