我正在嘗試通過 Cordova 插件為 webview 設定一個 cookie。我檢查了 cordova-android 源代碼,似乎有一個 CookieManager 介面。當我嘗試使用它時,當我檢查 webview 時沒有設定 cookie。
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
ICordovaCookieManager cookieManager = webView.getCookieManager();
cookieManager.setCookiesEnabled(true);
cookieManager.setCookie("https://com.myapp", "test=test");
}
請注意,我使用的是https://com.myapp作為主機,因為它是在hostname首選項中設定的。我也試過http://localhost和https://localhost..
如何使用ICordovaCookieManager來設定 cookie?
uj5u.com熱心網友回復:
我將回答我自己的問題,因為我找到了解決方案代碼確實有效!問題在于方案/主機名和檢查之間。
該方案實際上沒有設定 webView 位置,它總是回退到https://,即使你將它設定為app://.
然后,當我檢查 webview 時,默認情況下會加載它,file://因為我已AndroidInsecureFileModeEnabled設定為true,所以我確實需要重新加載 webview 并使用正確的 url https://com.myapp,最后我看到我的 cookie 或洗掉AndroidInsecureFileModeEnabled。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/515763.html
上一篇:如何使用rake任務檢查狀態
