如何在BlackBerry 10中为WebView设置cookie



任何人都可以帮助我在bb10

中的WebView中设置cookie

以下是我的审判,但它不起作用

在qml

     WebView {
            id: webview
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
            preferredWidth: 700
            settings.javaScriptEnabled: true
            settings.imageDownloadingEnabled: true
            settings.webInspectorEnabled: true
            url: constants.GET_BASEURL_Value() + subCatValue
            onCreationCompleted: {
                app.setWebCookies(webview, constants.GET_BASEURL_Value() + subCatValue);
            }
            preferredHeight: 1100
        }

在CPP中

    void ApplicationUI::setWebCookies(QObject* webObject, QString urlString) const {
    WebView* webview = qobject_cast<WebView*>(webObject);
    QUrl url = QUrl(urlString);
    WebCookieJar* m_pWebCookieJar = (webview->storage())->cookieJar();
    QSettings settings;
    QStringList cookies;
    cookies << "Cookie=" << settings.value("JSONID", "").toString().toUtf8();
    m_pWebCookieJar->setCookiesFromUrl(url, cookies);
    QStringList cookiesFromJar = m_pWebCookieJar->cookiesForUrl(url);
}

您可以直接从qml设置它:

webView.storage.cookieJar.setCookiesFromUrl(webView.url, ["test=test", "test1=test1"]);

最新更新