How to get HttpOnly cookie

3.3k views Asked by At

I need to get the HttpOnly cookies set as Session cookie in my java code.
To get non HttpOnly cookies I used Jsoup but now am stucked with HttpOnly cookies ?
Note : Don't know if it matters but the site from which I want to get HttpCookies is developed in ASP.net.

1

There are 1 answers

3
T.J. Crowder On

I would expect Jsoup to make those available:

Connection connection = Jsoup.connect("http://example.com");
Connection.Response response = connection.execute();

...then use the cookies map on response.

If the HttpOnly cookies aren't there, you may have to read the contents of the URL directly (e.g., via URLConnection or similar) before passing them on to JSoup.parse, and look for the cookie headers in that stream.


Side note: To get a Document after connecting as with the above, without repeating the request, use Connection#parse:

Document doc = connection.parse();

I just mention this because you're likely to want the document as well as the cookies.