Hello
I have problem with send POST method to server with JSON data. Actualy I tryed many idea, also idea with this forum but nothing helped me. So finally I whant to will ask in this forum. Basicly I have html file which below content which working.
<html>
<body>
<form method="POST" action="http://192.168.1.108/ask.cgi">
<input type="text" name="json"
value='{"ctrl":{"c":"gd","i":2}}' size="100">
<input type="submit">
</form>
</body>
</html>
<html>
<body>
<form method="POST" action="http://192.168.1.108/ask.cgi">
<input type="text" name="json"
value='{"ctrl":{"c":"gd","i":2}}' size="100">
<input type="submit">
</form>
</body>
</html>
To copy to clipboard, switch view to plain text mode
After I writed this text to let say test.html and execute, my serwer answer me correct, also in JSON data. So please me tell how to build POST method using Qt, and concret using QNetworkManager. I writed below code, but nothing happend. I see in wireshark how program traying something send but I do not get nothing.
QByteArray jsonString
= "{\"trl\":{\"c\":\"gd\",\"i\":256}}";
QUrl serviceURL
("http://192.168.1.108/ask.cgi/");
QNetworkRequest request(serviceURL);
request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
request.setRawHeader("Content-Length", postDataSize);
QNetworkAccessManager test;
connect(&test, SIGNAL(finished(QNetworkReply*)), &loop, SLOT(quit()));
QNetworkReply * reply = test.post(request, jsonString);
loop.exec();
qd " slot" << response;
QByteArray jsonString = "{\"trl\":{\"c\":\"gd\",\"i\":256}}";
QByteArray postDataSize = QByteArray::number(jsonString.size());
QUrl serviceURL("http://192.168.1.108/ask.cgi/");
QNetworkRequest request(serviceURL);
request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
request.setRawHeader("Content-Length", postDataSize);
QNetworkAccessManager test;
QEventLoop loop;
connect(&test, SIGNAL(finished(QNetworkReply*)), &loop, SLOT(quit()));
QNetworkReply * reply = test.post(request, jsonString);
loop.exec();
QByteArray response = reply->readAll();
qd " slot" << response;
To copy to clipboard, switch view to plain text mode
Bookmarks