How to get all cookies or cookie from android.webkit.CookieManager

basically, I went to facebook using webview. therefore, I do not know what cookies for which URLs are stored in the CookieManager. I don’t know if this is possible or not, but I know how to do it.

Now I need to get the page using Jsoup. but I need to send some cookie in order to get the page, otherwise the server will return an error pager to me.

I want it with Jsoup because I need information from the page

I have something like this, but all the time I get a page with an error:

Map<String, String> cookies = new HashMap<String, String>(); cookies.put(domain1, my_cookie1); cookies.put(domain2, my_cookie2); cookies.put(domain3, my_cookie3); cookies.put(domain4, my_cookie4); Document doc = Jsoup.connect(uri.toString()) .cookies(cookies) .timeout(10000) .get(); Log.e("title", doc.title()); 

my_cookie are obtained from CookieManager. and they are not null because I printed them.

I think the problem is with cookies. or not? is there any solution. I think I'm missing a cookie from CookieManager.

I need to get a page.

Edited by:

or is it possible to pass cookimanager to Jsoup? so that it can accept cookies from cookiemanager directly. or, can I know what cookies are needed to get my wish page?

+2
source share
1 answer

I solved the problem. First of all, I got the right cookies all the time. so then there was a problem. either I was wrong to integrate the cookie with Jsoup , or Jsoup was doing something wrong. therefore, I first got a page with an HttpUrlConnection , and then analyzed it using Jsoup. eg:

 URL form = new URL(uri.toString()); HttpUrlConnection connection1 = (HttpURLConnection)form.openConnection(); connection1.setRequestProperty("Cookie", my_cookie); connection1.setReadTimeout(10000); StringBuilder whole = new StringBuilder(); BufferedReader in = new BufferedReader( new InputStreamReader(new BufferedInputStream(connection1.getInputStream()))); String inputLine; while ((inputLine = in.readLine()) != null) whole.append(inputLine); in.close(); Document doc = Jsoup.parse(whole.toString()); 

Any advice on this code would be appreciated.

+2
source

All Articles