I have actually a logged session in my WebView.
But I use also httpclient to send and get data from the web. I saw on the internet that it's impossible to get the content of a WebView, so I needed to use my httpclient to get data from a webservice.
The problem is that this webservice uses sessions... and my session is in my WebView, so the httpclient doesn't have it and I can't access the content of the webservice.
I see many posts about this problem but I didn't understand the solution.
Here is what i did on my onPageStarted :
CookieManager mgr = CookieManager.getInstance();
Log.i( "URL", url );
Log.i("Cookie",mgr.getCookie("mywebsite.com"));
String cookie_string = mgr.getCookie("mywebsite.com");
if(cookie_string.length() > 1) {
Data.instance().getPref().edit().putString("cookie",cookie_string).commit();
}
I saw that I have this kind of things, so I hope those include session too:
(i remove the number)
__utma=......(number)......;
__utmc=number;
__utmz=number.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);
wt3_eid=%number%number;
wt3_sid=%number
Then i don't know what to do in order to set this cookie in my httpclient. I try that, with no success :
HttpClient client = new DefaultHttpClient();
BasicCookieStore cookieStore = new BasicCookieStore();
String login_cookie_string = Data.instance().getPref().getString("cookie", "");
String[] cookie_parts = null;
if(login_cookie_string.length()> 0)
{
//debug_view.setText(login_cookie_string);
Log.d("COOKIE", login_cookie_string);
cookie_parts = login_cookie_string.split(";");
for(int t=0;t < cookie_parts.length;t++)
{
String[] cookieContent = cookie_parts[t].split("=");
Cookie login_cookie = new BasicClientCookie(cookieContent[0],cookieContent[1]);
((BasicClientCookie) login_cookie).setDomain("mywebsite.com");
cookieStore.addCookie(login_cookie);
}
}
((AbstractHttpClient) client).setCookieStore(cookieStore);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…