我是Blackberry 10开发的新手,目前正在开展HTTP communication
演示。
任何人请与我分享HTTP request and response in QML source
的正确例子。
我正在为Blackberry 10应用程序使用Momentics IDE和QML源代码。
提前致谢。
答案 0 :(得分:3)
您应该看到HTTP sample。
答案 1 :(得分:1)
如果你想在你的Qml中使用这个JavaScript函数
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();
}
答案 2 :(得分:1)
尝试此语法..您可以从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);
}