1

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.

iAmLearning
  • 1,153
  • 3
  • 15
  • 28

1 Answers1

0

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.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • not working....there is no cookie header in body...not even the non HtmlOnly cookie is present in the body() method string – iAmLearning Jan 06 '14 at 12:01
  • @SushilKumar: You may have to do something like this: http://stackoverflow.com/a/16129860/157247 – T.J. Crowder Jan 06 '14 at 12:04
  • @SushilKumar: I just realized the `body` suggestion wasn't all that smart, the cookie headers are not (by definition!) in the body. So I've removed that. You may have to go down a layer, to `URLConnection` or similar. – T.J. Crowder Jan 06 '14 at 16:05