简体   繁体   English

如何“登录”到 web 应用程序并使用 Java 访问后续页面?

[英]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.

相关问题 如何在不重复代码的情况下在Java Web应用程序中包含jsp页面? - How do I include jsp pages in a Java web app without duplicating code? 如何通过登录创建简单的Web应用程序? - How do I make a simple web app with log-in? 如何为Web应用程序配置log4j.xml? - How do I configure log4j.xml for a web app? 您如何用Java打开网页? - How do you open web pages in Java? 我想从我的Java Web应用程序访问他们自己的保管箱的用户。 我怎样才能做到这一点? - I want to give access to users of their own dropbox from my java web app. How can I do that? 如何使用Ngrok将简单的Java HTTP客户端应用程序连接到Web资源? - How do I connect a simple Java HTTP client app to a web resource using Ngrok? 如何在Java Web App中使用Ajax将textfield的值和href值一起带到下一页? - How do I take the value of textfield along with the href value to the next page using Ajax in java web app? 如何在不使用Java身份验证的情况下停止直接访问网页(自定义标签) - how can i stop direct access to web pages without authentication in java (Custom Tag) 移动应用程序(例如 Facebook)如何在不使用浏览器的情况下访问网页? - How do mobile applications (Facebook for example) access web pages with out using a browser? 如何使用 java 的 Logger class 记录堆栈跟踪 - How do I log a stacktrace using java's Logger class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM