Android CookieManager设置cookie的安全属性

时间:2014-04-23 08:25:19

标签: android cookies webview

参考此

How to secure a cookie in android?

我想在我的Android应用程序中使用带有webview的cookie。我想设置cookie的安全属性。表示cookie仅与通过加密连接(HTTPS)发出的请求一起发送。请帮忙......

WebView webview = new WebView(getApplicationContext());
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(webview.getContext());
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.removeSessionCookie();
cookieManager.setCookie(url,value);
cookieSyncManager.sync();

webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}

});
webview.loadUrl(url)

1 个答案:

答案 0 :(得分:0)

您可以像这样设置Cookie属性

  

CookieManager.getInstance()setCookie方法(URL," JSESSIONID = 1ADF23ADS;    安全");。