Reputation: 7459
I am new in Blackberry 10 development and now currently working on HTTP communication
demo.
Anyone please share with me proper example of HTTP request and response in QML source
.
I am using Momentics IDE and QML source for Blackberry 10 applications.
Thanks in advance.
Upvotes: 2
Views: 528
Reputation: 11217
try this syntax.. you can get full code from sample
RequestHeaders::RequestHeaders(QObject* parent)
: QObject(parent)
, m_networkAccessManager(new QNetworkAccessManager(this))
{
}
/**
* RequestHeaders::getRequest()
*
* Setup an http get request using SSL if configured
*/
//! [0]
void RequestHeaders::getRequest()
{
const QUrl url("http://httpbin.org/get");
QNetworkRequest request(url);
if (AppSettings::isUsingHttps()) {
request.setUrl(QUrl("https://httpbin.org/get"));
QSslConfiguration config = request.sslConfiguration();
config.setPeerVerifyMode(QSslSocket::VerifyNone);
config.setProtocol(QSsl::TlsV1);
request.setSslConfiguration(config);
}
QNetworkReply* reply = m_networkAccessManager->get(request);
bool ok = connect(reply, SIGNAL(finished()), this, SLOT(onGetReply()));
Q_ASSERT(ok);
Q_UNUSED(ok);
}
Upvotes: 1
Reputation: 46
If you Want it in ur Qml u will with this JavaScript Function
function req()
{
var http = new XMLHttpRequest();
http.open("GET", url);//u will usse GET or POST based on the Url u request from it
var url = "url here";
http.open("GET", url, true);
http.onreadystatechange = function()
{
if (http.readyState == 4 && http.status == 200)
{
var x = http.responseText;//load data from link in x
var y = JSON.parse(x)//if Data generated as JSON File u can parse it using paserer fun
gdm.insertList(y)//insert Data in Grouped Data Model
console.log("ok");
}
else
{
console.log("tring");
}
}
http.send();
}
Upvotes: 1