Setting http get request parameters using Qt

curl, parse-platform, qt, rest

Solution

Unfortunately, QUrl::addQueryItem() is deprecated in qt5 but starting from there I found the QUrlQuery class which has an addQueryItem() method and can produce a query string that is acceptable for QUrl's setQuery() method so it now looks like this and works fine:

QUrl url("https://api.parse.com/1/login");
QUrlQuery query;

query.addQueryItem("username", "test");
query.addQueryItem("password", "test");

url.setQuery(query.query());

QNetworkRequest request(url);

request.setRawHeader("X-Parse-Application-Id", "myappid");
request.setRawHeader("X-Parse-REST-API-Key", "myapikey");

nam->get(request);

Thanks for the tip Chris.

Problem

I'm developing a basic application in Qt that retrieves data from Parse.com using the REST API. I went through some class references and the cURL manual but it's still not clear how you set the request parameters. For example, I'd like to authenticate a user. Here's the curl example provided by Parse: ``` curl -X GET \ -H "X-Parse-Application-Id: myappid" \ -H "X-Parse-REST-API-Key: myapikey" \ -G \ --data-urlencode 'username=test' \ --data-urlencode 'password=test' \ https://api.parse.com/1/login ``` I set the url and the headers like this ``` QUrl url("https://api.parse.com/1/login"); QNetworkRequest request(url); request.setRawHeader("X-Parse-Application-Id", "myappid"); request.setRawHeader("X-Parse-REST-API-Key", "myapikey"); nam->get(request); ``` which worked fine when there were no parameters, but what should I use to achieve the same as curl does with the --data-urlencode switch? Thanks for your time

Original source