I am trying to communicate with an external server to see if the user of the program has a license, so I must send a json to my server with the machine id to see the payment status of the account, then I should return a json content the information like number of days of the license, if it is paid etc.
QNetworkAccessManager am;
QNetworkRequest request(QUrl("http://localhost/ives/webserver/serverrequest.php"));
request.setHeader(QNetworkRequest::UserAgentHeader, "IVarejo");
QJsonObject root;
root.insert("tipoRequest", QJsonValue::fromVariant("validacao"));
QJsonDocument sendDoc;
sendDoc.setObject(root);
QString json = sendDoc.toJson(QJsonDocument::Compact);
qDebug() << "JSON: " << json;
QNetworkReply *reply = am.post(request, json.toUtf8());
qDebug() << "Resultado: " << reply->readAll();
php script:
<?php
if(isset($_POST))
echo json_encode($_POST);
?>
But I get an empty answer, unlike the browser when I send any data via form
JSON: "{\"tipoRequest\":\"validacao\"}"
Resultado: ""