Hi,
So I am writing an application on Ubuntu 16.04 in C++ using QT framework.
I can access RTU955 from terminal using curl as per instructions given by you here: JSON Access
When I send a curl command from within my application I receive a response that there is a parsing error:
{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}}
My guess is that I have done something really stupid with an escape character, any help would be appreciated, so my code, I create a QString that holds the curl command:
jsonAuthenticate = "curl -d";
jsonAuthenticate += " \"{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "00000000000000000000000000000000", "session", "login", { "username": "root", "password": "********" } ] }\"";
jsonAuthenticate += " http://192.168.2.1/ubus ";
Then I use QProcess
QString prErrors = ""; QString prStandard = "";
QProcess process;
process.start(jsonAuthenticate);
process.waitForFinished(5000); process.exitStatus();
prErrors = process.readAllStandardError();
prStandard = process.readAllStandardOutput();
I then tried to access via a QT class called QNetqorkAccessManager, but get the following error:
"<h1>Bad Request</h1>Invalid Request"
My Code:
jsonString = "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"call\",\"params\":[\"00000000000000000000000000000000\",\"session\",\"login\",{\"username\":\"root\",\"password\":\"*********\"}]}";
networkManager = new QNetworkAccessManager(this);
serviceUrl = QUrl("http://192.168.2.1/ubus");
request.setUrl(serviceUrl);
request.setRawHeader("Content-Type","application/json");
request.setRawHeader("Content-Length",postDataSize);
QEventLoop eventLoop;
networkManager->post(request,jsonString);
reply = networkManager->get(request);
connect(reply,SIGNAL(finished()),&eventLoop,SLOT(quit()));
eventLoop.exec();
QByteArray data = reply->readAll();