c++ - Make HTTP POST request with a list of named parameters in Qt -
i need make http post request server qt application.
the post request contain list of named values, i.e. key/value pairs. alphanumeric strings, can contain special characters such quotes, spaces, etc.
what canonical way of doing type of post request in qt?
qurl params; params.addqueryitem("key1", "value1"); params.addqueryitem("key2", "value2"); qurl resource("http://server.com/form.php"); qnetworkaccessmanager* manager = new qnetworkaccessmanager(this); connect(manager, signal(finished(qnetworkreply*)), this, slot(handleendofrequest(qnetworkreply*))); qnetworkrequest request(resource); //force content-type header request.setheader(qnetworkrequest::contenttypeheader, "application/x-www-form-urlencoded"); manager->post(request, params.encodedquery());
this code assumes current object qobject (passed parent qneworkaccessmanager , slots declaration)
Comments
Post a Comment