在web视图Android的设置cookie视图、web、cookie、Android

由网友(永不止步)分享简介:我想设定一些饼干在我的的WebView 打开与同一个会话,我有我的应用程序的浏览器。 I'm trying to set some cookies on my WebView to open a browser with the same session that I have on my app. 我读了很多答案...

我想设定一些饼干在我的的WebView 打开与同一个会话,我有我的应用程序的浏览器。

I'm trying to set some cookies on my WebView to open a browser with the same session that I have on my app.

我读了很多答案,但他们不为我工作。我发现的唯一的解决办法是在C中的cookie数据的使用loadURL ,硬$ C $在 extraHeaders ,但预期这仅适用于该请求,并不会十个分量的会话。

I read a lot of answers but they don't work for me. The only solution I've found is in the loadUrl, hardcode the cookie data in extraHeaders, but as expected this only works for this requests, and doesn't mantain the session.

在code,我有是:

CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(mWebView.getContext());
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.removeSessionCookie();
cookieManager.setCookie("http://xx.xxx.xxx.com","mid="+MySession.GetSession().sessionId+" ; Domain=.xxx.com");
cookieSyncManager.sync();

String cookie = cookieManager.getCookie("http://xx.xxx.xxx.com");

Log.d(LOGTAG, "cookie ------>"+cookie);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new TuWebViewClient());
mWebView.loadUrl("http://xx.xx.xxx.com");

的getCookie()返回正确的数据,但是当我从服务器读取的饼干,这些都是空的。哪里不对?请指教。 谢谢!

getCookie() returns the correct data, but when I read the cookies from the server, those are empty. What is wrong? Please advise. Thank you!!!

推荐答案

解决!!!!问题是web视图,我不知道发生了什么,但如果我创建了

Solved!!!! the problem is with the webView, I dont know what happend, but If I create the

WebView webView = new WebView(Activity.this);

它的工作原理。如果我读了活动的WebView与 findViewById()这是行不通的。

另外,如果你需要设置的,你从一个网站收到previously Cookie的列表。 所有你需要做的就是使用 for循环经历,并设置所有的人。它帮助我解决的情况

Also if you need to set a list of cookies that you received previously from a website. All you have to do is use a for-loop to go through and set all of them . It helped me to solve the situation

阅读全文

相关推荐

最新文章