简体   繁体   English

如何获取HttpOnly cookie

[英]How to get HttpOnly cookie

I need to get the HttpOnly cookies set as Session cookie in my java code . 我需要在我的Java代码中将HttpOnly cookie设置为Session cookie
To get non HttpOnly cookies I used Jsoup but now am stucked with HttpOnly cookies ? 为了获得非HttpOnly cookie,我使用了Jsoup,但现在却卡在了HttpOnly cookie中?
Note : Don't know if it matters but the site from which I want to get HttpCookies is developed in ASP.net. 注意:不知道这是否重要,但是要从中获取HttpCookies的站点是在ASP.net中开发的。

I would expect Jsoup to make those available: 我希望Jsoup可以提供这些功能:

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

...then use the cookies map on response . ...然后在response上使用cookies映射。

If the HttpOnly cookies aren't there, you may have to read the contents of the URL directly (eg, via URLConnection or similar) before passing them on to JSoup.parse , and look for the cookie headers in that stream. 如果不存在HttpOnly cookie,则可能必须先直接读取URL的内容(例如,通过URLConnection或类似方法),然后再将它们传递给JSoup.parse ,然后在该流中查找cookie头。


Side note: To get a Document after connecting as with the above, without repeating the request, use Connection#parse : 旁注:要在进行上述连接后获取Document ,而无需重复请求,请使用Connection#parse

Document doc = connection.parse();

I just mention this because you're likely to want the document as well as the cookies. 我之所以这样提一下,是因为您可能想要文档以及cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM