qt rest api
QUrl url;
url.setScheme(“http”);
url.setHost(“api.thingspeak.com”);
url.setPath(“/channels/”+CHNum+”/feeds.json”);
url.setQuery(“api_key=”+RDKey+”&results=10”);
request.setUrl(url);
reply=nwManager->get(request);
qt rest api
QUrl url;
url.setScheme(“http”);
url.setHost(“api.thingspeak.com”);
url.setPath(“/channels/”+CHNum+”/feeds.json”);
url.setQuery(“api_key=”+RDKey+”&results=10”);
request.setUrl(url);
reply=nwManager->get(request);
qt rest api
QUrl myurl;
myurl.setScheme(“http”); //https also applicable
myurl.setHost(“api.thingspeak.com”);
myurl.setPath(“/update.json”);
qt rest api
QObject::connect(restclient, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply *)));
qt rest api
QUrlQuery querystr;
querystr.addQueryItem(“api_key”,WRKey);
querystr.addQueryItem(“field1”,”25”);
querystr.addQueryItem(“field2”,”72”);
querystr.addQueryItem(“field3”,”900”);
myurl.setScheme(“https”);
myurl.setHost(“api.thingspeak.com”);
myurl.setPath(“/update”);
myurl.setQuery(querystr);
request.setUrl(myurl);
reply = restclient->get(myurl);
qDebug() << reply->readAll();
qt rest api
{
“api_key”:”XXXXXXXX XXXXXXXX”,
“field1”:”25”,
“field2”:”72”,
“field3”:”900”
}
qt rest api
QJsonDocument jsdoc;
jsdoc = QJsonDocument::fromJson(reply->readAll());
QJsonObject jsobj = jsdoc.object();
QJsonArray jsarr = jsobj[“feeds”].toArray();
foreach (const QJsonValue &value, jsarr) {
QJsonObject jsob = value.toObject();
qDebug() << jsob[“entry_id”].toInt();
qDebug() << jsob[“field1”].toString();
qDebug() << jsob[“field2”].toString();
qDebug() << jsob[“field3”].toString();
qDebug() << jsob[“created_at”].toString();
}
reply->deleteLater();
qt rest api
QNetworkRequest request;
request.setUrl(myurl);
request.setHeader(QNetworkRequest::ContentTypeHeader,
”application/json”);
qt rest api
//Prepare querystr similar to above steps
request.setHeader(QNetworkRequest::ContentTypeHeader, “application/x-www-form-urlencoded”);
QByteArray postdata = Qvariant(querystr).toByteArray();
restclient->post(myurl,postdata);
qt rest api
QNetworkAccessManager *restclient; //in class
restclient = new QNetworkAccessManager(this); //constructor
QNetworkReply *reply = restclient->post(request,payload);
qDebug() << reply->readAll();
qt rest api
QVariantMap feed;
feed.insert(“api_key”,WRKey);
feed.insert(“field1”,QVariant(tval).toString());
feed.insert(“field2”,QVariant(hval).toString());
feed.insert(“field3”,Qvariant(pval).toString());
QByteArray payload=QJsonDocument::fromVariant(feed).toJson();
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us