Firstly before I will start post, I whant to tell that I read this topic
Correct format for HTTP POST using QNetworkRequest
I using this idea but for me is does not working. I also read a few other topic but all time I do not have solve. May be therefore because I somethig missed (for sure).
Now I will show what request is work with html file
<html>
<body>
<form method="POST" action="http://192.168.1.108/acces.cgi">
<input type="text" name="json"
value='{"method":{"ok":"get","number":1}}' size="100">
<input type="submit">
</form>
</body>
</html>
After send this request I get answer in browser. So request JSON is correct for sure.
Now I whant try send this same request but using Qt so I have written below code but I only get warring
qt.network.ssl: QSslSocket: cannot resolve SSlv2_client_method
qt.network.ssl: QSslSocket: cannot resolve SSlv2_server_method
And My Code
QUrl url("http://192.168.1.108/acces.cgi"); // request to local host
QNetworkRequest *request = new QNetworkRequest(url);
request>setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
manager = new QNetworkAccessManager();
QObject::connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(HandledDataFromNetwork(QNetworkReply*)));
// prepare JSON string
QByteArray array= "{\"method\":{\"ok\":\"get\",\"number\":\"1\"}}";
// and Send
reply = manager->post(*request, array);
// next I wait for signal and try recive in slot
void MyClass::HandledDataFromNetwork(QNetworkReply *reply)
{
qDebug() << "content" << reply->readAll();
}
But expect warrning I not get nothing more.
Ps. Sorry for that how it looks code in Qt I do not can correct preper better
EDIT: SOLVED !!!
Answer is using QUrlQuery class. So code should be looks like below:
QUrl url("http://192.168.1.109/ask.cgi");
QUrlQuery query;
query.setQuery("json={\"ctrl\":{\"c":\"gd\",\"i\":6}}");
url.setQuery(query);
QNetworkRequest req(url);
QNetworkAccessManager test;
QEventLoop loop;
connect(&test, SIGNAL(finished(QNetworkReply*)), &loop, SLOT(quit()));
QNetworkReply * reply = test.get(req);
loop.exec();
:)