I want to send an HTTP Post request once a user type an incorrect password. I am sure that my code other than the HTTP request I send works, however when I try to send a GET request it works, but POST request doesn't. I suppose it is connected to the Qt lifecycle. I have tried various of things, but nothing worked.
Here was my initial code.
#ifdef __cplusplus
extern "C"
{
#endif
JNIEXPORT void JNICALL Java_tech_secureme_SecureMeDeviceAdminReceiver_handleHttpRequest(JNIEnv env, jobject obj, jint n)
{
QNetworkRequest request(QUrl("https://secureme.live/incorrect_password"));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QNetworkAccessManager *manager = new QNetworkAccessManager;
QObject::connect(manager, &QNetworkAccessManager::finished,
[](QNetworkReply *reply)
{
if (reply->error())
{
NotificationClient::getInstance()->setNotification("err", reply->errorString());
}
reply->deleteLater();
});
QJsonObject json;
json["key"] = "value";
QJsonDocument jsonDoc(json);
QByteArray jsonData = jsonDoc.toJson();
manager->post(request, jsonData);
}
#ifdef __cplusplus
}
#endif
This JNI function gets called whenever user types his password incorrectly. Again I am sure that this part works.
Why does GET request works and POST doesn't ? How can I fix that ?