2

我是 Blackberry 10 开发的新手,现在正在做HTTP communication演示。

任何人请与我分享正确的例子HTTP request and response in QML source

我正在为 Blackberry 10 应用程序使用 Momentics IDE 和 QML 源代码。

提前致谢。

4

3 回答 3

3

您应该看到HTTP 示例

于 2013-08-16T22:10:45.927 回答
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();
    }
于 2013-08-29T07:38:51.217 回答
1

试试这个语法..你可以从示例中获得完整的代码

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);
}
于 2013-09-03T17:16:31.987 回答