how to get all cookies or cookie's url from android.webkit.CookieManager
Asked Answered
T

1

2

mainly, i have loged into facebook using webview. so, i don't know which cookies for which urls are saved into CookieManager. i don't know whether it is possible or not, but i have know idea how to do it.

now, i need to get a page using Jsoup. but i need to pass some cookie also to get the page, otherwise server will return me an error pager.

i want it with Jsoup, because i need some information from the page

i have trying something like this, but all the time i am getting the error page:

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's are get from CookieManager. and they are not null, because i have printed them.

i think the problem is with cookies. or not? is there any solution. i think i am missing some cookie from CookieManager.

i need to get the page.

Edited:

or, is it possible to pass the cookimanager to Jsoup ? so, that it can take the cookie from cookiemanager directly. or, can i know which cookies are needed for getting my desire page?

Tamarah answered 17/2, 2013 at 19:21 Comment(0)
T
2

i have solve the problem. first of all i was getting the right cookie all time. so what was the problem then. either i was wrong to integrate the cookie with Jsoup or Jsoup was doing something wrong. so, first i have get the page with HttpUrlConnection and then parse it with Jsoup. like this:

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 about this code would be appreciated.

Tamarah answered 18/2, 2013 at 0:8 Comment(2)
Which dependecies do you use for HttpUrlConnection instance?Hotspur
@Hotspur I have used the default java(Android) HttpUrlConnection. I haven't used any extra dependecie(s)Tamarah

© 2022 - 2024 — McMap. All rights reserved.