机器人的WebView读取cookies [英] Android webview read cookies
本文介绍了机器人的WebView读取cookies的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的code,显示在web视图网页:
I have the following code to display a webpage in a webview:
WebView myWebView = (WebView) findViewById(R.id.webView1);
myWebView.loadUrl("http://the.url.com");
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
现在我想读的WebView的饼干。这可能吗?
Now I want to read cookie of the webview. Is this possible?
推荐答案
这是一个比较晚,但它可能会帮助别人
It was a quite late , but it might help someone
您可以通过此获得cookie值
you can get the cookie value by this
public String getCookie(String siteName,String CookieName){
String CookieValue = null;
CookieManager cookieManager = CookieManager.getInstance();
String cookies = cookieManager.getCookie(siteName);
String[] temp=cookies.split(";");
for (String ar1 : temp ){
if(ar1.contains(CookieName)){
String[] temp1=ar1.split("=");
CookieValue = temp1[1];
}
}
return CookieValue;
}
修改
点要注意:
Edit
Point to notice:
如果您正在加载的URL如 http://sitedomain.com
(不含 WWW
)的 siteName的
与 WWW
将无法使用此方法的工作。
If you are loading URL like http://sitedomain.com
(without www
), the siteName
with www
will not work with this method.
这篇关于机器人的WebView读取cookies的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文