WebView 和 HTTPClient 之间共享 Cookie?
我正在构建的 Android 应用程序需要用户进行 Web 身份验证才能进行数据调用。在 Adobe AIR 和后来的 iPhone 中,我们通过在 Webview 等效页面中渲染登录页面并在用户登录时设置 cookie 来实现此目的。后续数据调用使用相同的 Cookie Jar,因此被视为已通过身份验证。
在 Android 版本中,我使用 WebView 对用户进行身份验证,然后完成后,我使用 DefaultHttpClient 进行数据调用,但是我似乎无法在第二次调用时加载数据。
我缺少一些饼干陷阱吗?我想 HTTPClient 和 WebView 将共享相同的 Cookie 空间。我错了吗?
An Android app I am building requires web authentication for users to make data calls. In Adobe AIR and later the iPhone, we did this by rendering a login page in a webview-equivalent page and setting a cookie when the user signs in. Subsequent data calls use the same Cookie Jar and so are seen as authenticated.
In the Android version, I authenticate the user using a WebView and then once thats done, I make a data call using DefaultHttpClient, however I cant seem to load the data on the second call.
Is there some cookie gotcha I am missing? I imagine the HTTPClient and WebView would share the same Cookie space. Am I wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我最终起作用的代码片段(它的伪代码的一部分已从我的项目中删除,并且诸如通过单例调用 MyApplication 之类的一些内容更多地说明了要做什么,而不是如何通过最佳实践来完成) :
http://gist.github.com/610754
Here is my code snippet that finally worked (its pseudo code as in parts of it were ripped out of my project and some things like calling MyApplication via a Singleton were more to illustrate what to do rather than how it should be done with best practices):
http://gist.github.com/610754