使用 DefaultHttpClient 和 Swingworker 实现 cookie 持久化
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将任何想要的参数传递给 < 的构造函数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.