How to get HttpOnly cookie

天涯浪子 提交于 2019-12-13 17:42:46

问题


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:


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.



来源:https://stackoverflow.com/questions/20948159/how-to-get-httponly-cookie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!