Can anyone point me to a simple way to make calls to a REST service using Qt4? I cannot find any decent documentation on how to do this. Right now I have something like:
int NetworkClient::attemptLogin( QString username, QString password, int & error ) {
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QObject::connect(manager, SIGNAL(finished(QNetworkReply *)), SLOT(slotRequestFinished(QNetworkReply *)));
QNetworkRequest request;
request.setUrl(QUrl("http://192.168.20.155:3000/api/rest/user?id=" + username));
request.setHeader(QNetworkRequest::ContentTypeHeader, "text/xml");
QNetworkReply *reply = 0;
reply = manager->get(request);
qDebug() << reply;
Am I even close?
Here is my calling code:
void LoginWindow::attemptLogin() {
int loginError;
QString username = usernameField->text();
QString password = passwordField->text();
int minutes = net.attemptLogin( username, password, loginError );
if ( minutes ) {
attemptLoginSuccess( username, password, minutes );
} else {
attemptLoginFailure( loginError );
}
}
Here's my take...
Your function is close to what I use when calling REST services. What I do is create one function for each http verb.
This is my post function (note the support for SSL and Basic Authorization)
Here is how I ended up resolving my issue: https://bitbucket.org/libki-kms/libki-client/src/917e8201c997a9f37b57420c0df68c8751527f2a/networkclient.cpp?at=master
Thanks for help all!