在webview中加载某些页面时,我几次收到WebView中显示的请求标题或会话Cookie太大这个异常。
在WebView中加载URL的方式:
webView = (WebView) findViewById(R.id.idWebView);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
Map<String, String> headers = new HashMap<>();
headers.put("Accept-Language", getLanguage());
webView.loadUrl(url, headers);
为了清楚起见,即使没有 headers.put(“Accept-Language”,getLanguage()),也会发生这种情况;
我不确定这是否应该在Android或服务器端修复。 有没有人在Android WebViews上遇到过类似的问题?
这是此例外的控制台日志:
请求标题:{X-Requested-With = ch.denner.inhouse,Cookie = store = de; ls_mage翻译存储=%7B%7D; ss_94680522_mage翻译存储=%7B%7D; MAGE-翻译存储=%7B%7D; ss_94680522_mage翻译文件版本=%7B%7D; MAGE-翻译文件版本=%7B%7D; ls_mage翻译文件版本=%7B%22version%22%3A%224a03928408a7b94f82c301d4277eff8aee6c47f7%22%7D; ss_94680522_mage缓存存储=%7B%7D; ss_94680522_mage缓存存储截面-无效=%7B%7D; ls_mage缓存超时=%222018-04-11T08%3A55%3A05.513Z%22; ls_recently_viewed_product =%7B%7D; ss_94680522_recently_viewed_product =%7B%7D; ls_recently_viewed_product_previous =%7B%7D; ss_94680522_recently_viewed_product_previous =%7B%7D; ls_recently_compared_product =%7B%7D; ss_94680522_recently_compared_product =%7B%7D; ls_recently_compared_product_previous =%7B%7D; ss_94680522_recently_compared_product_previous =%7B%7D; ls_product_data_storage =%7B%7D; ss_94680522_product_data_storage =%7B%7D; ss_13756572_mage翻译存储=%7B%7D; ss_13756572_mage翻译文件版本=%7B%7D; ss_13756572_mage缓存存储=%7B%7D; ss_13756572_mage缓存存储截面-无效=%7B%7D; ss_13756572_recently_viewed_product =%7B%7D; ss_13756572_recently_viewed_product_previous =%7B%7D; ss_13756572_recently_compared_product =%7B%7D; ss_13756572_recently_compared_product_previous =%7B%7D; ss_13756572_product_data_storage =%7B%7D; ss_69184443_mage翻译存储=%7B%7D; ss_69184443_mage翻译文件版本=%7B%7D; ss_69184443_mage缓存存储=%7B%7D; ss_69184443_mage缓存存储截面-无效=%7B%7D; ss_69184443_recently_viewed_product =%7B%7D; ss_69184443_recently_viewed_product_previous =%7B%7D; ss_69184443_recently_compared_product =%7B%7D; ss_69184443_recently_compared_product_previous =%7B%7D; ss_69184443_product_data_storage =%7B%7D; ss_11203415_mage翻译存储=%7B%7D; ss_11203415_mage翻译文件版本=%7B%7D; ss_11203415_mage缓存存储=%7B%7D; ss_11203415_mage缓存存储截面-无效=%7B%7D; ss_11203415_recently_viewed_product =%7B%7D; ss_11203415_recently_viewed_product_previous =%7B%7D; ss_11203415_recently_compared_product =%7B%7D; ss_11203415_recently_compared_product_previous =%7B%7D; ss_11203415_product_data_storage =%7B%7D; ss_51744436_mage翻译存储=%7B%7D; ss_51744436_mage翻译文件版本=%7B%7D; ss_51744436_mage缓存存储=%7B%7D; ss_51744436_mage缓存存储截面-无效=%7B%7D; ss_51744436_recently_viewed_product =%7B%7D; ss_51744436_recently_viewed_product_previous =%7B%7D; ss_51744436_recently_compared_product =%7B%7D; ss_51744436_recently_compared_product_previous =%7B%7D; ss_51744436_product_data_storage =%7B%7D; ss_98351072_mage翻译存储=%7B%7D; ss_98351072_mage翻译文件版本=%7B%7D; ss_98351072_mage缓存存储=%7B%7D; ss_98351072_mage缓存存储截面-无效=%7B%7D; ls_private_content_version = a34cb889d50dcc9485592bb349ad209b; ls_mage缓存存储截面-无效=%7B%7D; ss_98351072_recently_viewed_product =%7B%7D; ss_98351072_recently_viewed_product_previous =%7B%7D; ss_98351072_recently_compared_product =%7B%7D; ss_98351072_recently_compared_product_previous =%7B%7D; ss_98351072_product_data_storage =%7B%7D; ls_mage缓存存储=%7B%22cart%22%3A%7B%22summary_count%22%3A0%2C%22subtotalAmount%22%3Anull%2C%22subtotal%22%3A%22%3Cspan%20class%3D%5C%22price %5C%22%3EFr。%20%C2%A00.00%3C%2Fspan%3E%22%2C%22possible_onepage_checkout%22%3Atrue%2C%22items%22%3A%5B%5D%2C%22extra_actions%22% 3A%22%22%2C%22isGuestCheckoutAllowed%22%3Atrue%2C%22website_id%22%3A%221%22%2C%22subtotal_incl_tax%22%3A%22%3Cspan%20class%3D%5C%22price%5C%22% 3EFr。%20%C2%A00.00%3C%2Fspan%3E%22%2C%22subtotal_excl_tax%22%3A%22%3Cspan%20class%3D%5C%22price%5C%22%3EFr。%20%C2% A00.00%3C%2Fspan%3E%22%2C%22denner_total_bottles%22%3A0%2C%22denner_subtotal_catalog_discount%22%3A0%2C%22data_id%22%3A1523434856%7D%2C%22customweb_external_checkout_widgets%22%3A%7B%22html% 22%3A%5B%5D%2C%22data_id%22%3A1523434855%7D%2C%22customer%22%3A%7B%22data_id%22%3A1523434855%7D%2C%
答案 0 :(得分:2)
<强>解决方案强>
我将以下代码添加到我的自定义WebView中(您可以将其添加到任何您想要的位置)。
private void clearCookies() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
CookieManager.getInstance().removeAllCookies(null);
CookieManager.getInstance().flush();
return;
}
CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(getContext());
cookieSyncManager.startSync();
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
cookieManager.removeSessionCookie();
cookieSyncManager.stopSync();
cookieSyncManager.sync();
}
因此,在加载任何网址之前,我只需拨打 clearCookies()