I have a webservice that I need to POST some data to using Qt. I figured that I can use a QByteArray when POSTing to the web service.
My question is, how can I forma
Updating alexisdm answer to Qt5:
// Setup the webservice url
QUrl serviceUrl = QUrl("http://your.url");
QByteArray postData;
QUrlQuery query;
query.addQueryItem("param1","string1");
query.addQueryItem("param2","string2");
postData = query.toString(QUrl::FullyEncoded).toUtf8();
// Call the webservice
QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
connect(networkManager, SIGNAL(finished(QNetworkReply*)),
SLOT(onPostAnswer(QNetworkReply*)));
QNetworkRequest networkRequest(serviceUrl);
networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
networkManager->post(networkRequest,postData);
Don't forget to include
QT += network
in .pro.