Reputation: 361
I'm new to Qt and have some difficulties regarding a post request to a PHP file and reading the response.
Everything I found about how to implement a POST request in Qt 5 is somehow outdated (Qt 4.x) and does not work properly, OR doesn't help me because of some lack of knowledge.
For example, the php file looks like this:
<?php
// read param1
$value = $_POST['param1'];
// Do some stuff here
// return some text
echo $value;
?>
All I want to do is this:
Is there a small example of c++-code, how to implement this task with QT5?
Upvotes: 2
Views: 5936
Reputation: 90853
Did you try QNetworkAccessManager
?
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
manager->post(QNetworkRequest(QUrl("http://example.com/yourscript.php")), data);
data
is a QByteArray
that you can generate from a QString if needed.
Upvotes: 10