使用 DefaultHttpClient 和 Swingworker 实现 cookie 持久化

发布于 2024-10-01 03:25:54 字数 332 浏览 1 评论 0原文

我有一个 swingworker 类,调用一个使用 DefaultHttpClient 建立与安全网站的持久连接的方法。当我登录并使用 swingworker 实例向站点发出请求后,swingworker 实例将关闭(正常情况)。我的问题是:如何维护对站点的持久登录,以便我可以向 Swingworker 的另一个实例发出未来请求 - 无需再次登录站点(我已经创建了一个会话)?我无法将 DefaultHttpClient 的实例传递给 swingworker 类(至少我不知道如何)。 我考虑过将 cookie 数据保存到文件中,然后将其传递给 DefaultHttpClient...但是我是否遗漏了一些更基本的东西?

谢谢, 抢

I have a swingworker class calling a method that uses DefaultHttpClient to establish a persistent connection to a secure web site. After I login and make a request to the site with an instance of swingworker, the instance of swingworker closes (as is normal). My question is: how do I maintain the persistent login to the site so I can make a future request with another instance of swingworker - without logging into the site again (I have created a session)? I cannot pass an instance of DefaultHttpClient to the swingworker class (at least I don't know how).
I have considered saving the cookie data to a file and then passing it the the DefaultHttpClient... but am I missing something more fundamental?

Thanks,
Rob

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桃酥萝莉 2024-10-08 03:25:54

您可以将任何想要的参数传递给 < 的构造函数code>SwingWorker 子类,如本示例中建议的那样,您可以在每次调用时执行此操作。

You can pass any parameter you want to the constructor of your SwingWorker subclass, as suggested in this example, and you can do so with each invocation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文