WebView 和 HTTPClient 之间共享 Cookie?

发布于 2024-09-02 07:19:57 字数 328 浏览 6 评论 0原文

我正在构建的 Android 应用程序需要用户进行 Web 身份验证才能进行数据调用。在 Adob​​e 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 技术交流群。

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

发布评论

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

评论(1

半边脸i 2024-09-09 07:19:57

这是我最终起作用的代码片段(它的伪代码的一部分已从我的项目中删除,并且诸如通过单例调用 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

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