[英]How do I “log in” to a web app and access subsequent pages using Java?
I want to write a Java program that'll access a few web pages that requires logging in. How would I keep the session cookie resulting from logging in so I can access those pages?我想编写一个 Java 程序,该程序将访问一些需要登录的 web 页面。我将如何保留 session cookie,以便我可以访问这些页面?
Commons HTTPClient has all the capability to do what you want. Commons HTTPClient具有执行您想要的所有功能。 You can do any sort of authentication and cookie handling that you need.您可以进行所需的任何类型的身份验证和 cookie 处理。 Here is the code for the CookieDemoApp .这是CookieDemoApp的代码。
You'll probably want to use CookieManager (you could also look at its superclass CookieHandler ).您可能想要使用CookieManager (您也可以查看它的超类CookieHandler )。 I don't know whether the standard URLConnection
class will automatically store cookies for you, though.不过,我不知道标准URLConnection
class 是否会自动为您存储 cookies 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.